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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.