<?php
# simple PHP crypt() test script.
if (isset($_POST['submit'])) {
//$password = crypt("My1sTpassword"); // let salt be generated
$password = crypt("test"); // let salt be generated
# You should pass the entire results of crypt() as the salt for comparing a
# password, to avoid problems when different hashing algorithms are used. (As
# it says above, standard DES-based password hashing uses a 2-character salt,
# but MD5-based hashing uses 12.)
$user_input = crypt($_POST['userpass'], $password);
echo "crypt hash: <font color=blue>$user_input</font><p>";
if ($user_input == $password) {
echo "<font color=green>Password verified!</font>";
} else {
echo "<font color=red>Password wrong!</font>";
}
} else {
?>
<form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
<b>Enter Password:</b><br>
<input type="password" name="userpass" size="30">
<p><input type="submit" name="submit" value="submit">
</form>
<?php
}
?>