<title>Untitled Document</title> <script src="../jquery-1.6.min.js" type="text/javascript"></script> </head> <body> <form method="post" action="test.php"> Password:<input type="password" name="name"/> //user enters the password </form> </body> </html>The authentication page on the server
<?php
$secret_password=md5('password'); //md5 of the password stored on the server
$entered_password=md5($_POST['name']); //password entered by the user
if($entered_password==$secret_password)
$result = 'Correct Password';
else
$result='Incorrect password';
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title></title>
<style type="text/css">
</style>
</head>
<body>
<?php
echo $result; //It is best practise to echo out the results inside the HTML body.
?>
</body>
</html>
The password stored is just hardcoded in this case, but can be retrieved from the Database instead.SHA1 is another hashing method which is more secure, with a 160 bit encryption.
eg: sha1('$string');
sha1_file('$file'); //calculate the sha1 of a file
No comments:
Post a Comment