I have a MySQL database of users, each has login and password.
When creating users, their password is encrypted by this function: crypt($password, CRYPT_STD_DES);
I have a problem with logging in: user enters his password to a form, this is encrypted (same as above), and compared to data from database, but even if both are string type and seem equal, the strcmp() function returns -1. Can you please help me with this?
Example:
password entered: admpass
password in database: 1$JQRIFplqxNE
encrypted entered password: 1$JQRIFplqxNE
… and still, strcmp() returns -1. === operator returns 0. And both are string type.
My codes:
form:
[php]
echo "<form action=“login.php” method=“post”>
<input type=“hidden” name=“id-form” value=“log” />
Login:
Password:
"; [/php]script for processing form data:
[php]
$login = $_POST[‘login’];
$encrypted_entered_pass = crypt($_POST[‘pass’], CRYPT_STD_DES);
/// I tried these functions, but it didn’t help
$encrypted_entered_pass = trim($encrypted_entered_pass);
$encrypted_entered_pass = implode(str_split($encrypted_entered_pass));
/// data already taken from database
$db_pass = trim($user[‘password’]);
$db_pass = implode(str_split($db_pass));
if (strcmp($encrypted_entered_pass, $db_pass) <> 0) $loginError = 1;
[/php]