strcmp() problem

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]

Clupko, this topic was marked solved, but, no replies were given. Did you solve it yourself or do you still need help with it?

I managed to get solution myself, eventually :slight_smile:

Okay, since you did not post a solution or even tell us that you solved it, I was just checking.
Glad you solved it. Good luck with your project…

Sorry, I didn’t realize…
I found out syntax I used was incorrect, and solved the problem using what I found on php.net’s User Contributed Notes for function crypt() - specifically I used what user ircmaxell at php dot net posted.

Sponsor our Newsletter | Privacy Policy | Terms of Service