Authenticating with user id and password using PHP

In this example, I use the form processing using and authentication.

<?php
function Insert_Data()
 {
   echo $_POST['title']. " is what you typed.";
}
function Display_Upload()
 {

 $HTMLDOCS = <<<HTML1
<html>
<body>
<form action="add_data.php" method="post" 
enctype="multipart/form-data">
<table>
<tr>
<td>User:</td>
<td><input type="text" name="userid" size="50"/>
</td>
</tr>
<tr>
<td>Password:</td>
<td><input type="password" name="password" size="50"/>
</td>
</tr>
<tr>
<td>Title:</td>
<td><input type="text" name="title" id="title" size="50"/>
</td>
</tr>
<tr><td></td><td>
 <input type="submit" name="submit" value="Submit Form"></td></tr>
</table>
</form>
</body>
</html>
HTML1;
print $HTMLDOCS;
}
// Main Program
$c_userid = "xxasdfasdf"; # 
$c_password = "xxsdfasdf"; # 

if (!isset($_POST["title"]))
 {
    Display_Upload();
 } else
 {
    if ((crypt($_POST["userid"],'xx')==$c_userid) && (crypt($_POST["password"],'xx')==$c_password))
 {
    Insert_Data();
} else
 {
    echo "Authentication Failed";
 }

 }
?>

In the example above, the $c_userid and $c_password variable is the userid and the password you want user to enter before they can proceed with the form. You must use the encrypted form of the string here. From your php script, get the output by using the crypt(useridstring,’xx’). Use the following script for that.

<?php
echo crypt("useridstring",'xx');
?>
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s