Jump to content

crypt error


sungpeng

Recommended Posts

When using crypt, you should always use a salt. Using crypt() without a salt can produce varying and inconsistent results. Also, while function but as a matter of practice, you should reference baked-in constructs in lowercase form ( crypt() Vs. CRYPT() ), unless otherwise noted by the PHP manual.

 

Try this:

<?php
$salt = "asdfghjkl";
$password = crypt('mypassword', $salt); 

if (crypt($user_input, $salt) == $password) {
     echo "Password verified!";
}
else {
     echo "unsuccessful";
}
?>

 

BTW: While fine for learning, I would not consider the above as a login method for a production system. There are better, more secure ways of doing authentication.

Link to comment
https://forums.phpfreaks.com/topic/251232-crypt-error/#findComment-1288586
Share on other sites

This works just fine:

 

<?php

$salt = "asdfghjkl";
$user_input = 'mypassword';
$password = crypt('mypassword', $salt); 

if (crypt($user_input, $salt) == $password) {
     echo "Password verified!";
}
else {
     echo "unsuccessful";
}

?>

 

Notice that I specifically set $user_input. So if it didn't work for you, it would indicate that you're not setting the $user_input variable.

Link to comment
https://forums.phpfreaks.com/topic/251232-crypt-error/#findComment-1288591
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.