0

The following code is what I've used to encrypt a password in PHP...

$password = sha1(sha1($_POST['password']).sha1("mySalt@$#(%"));

What code can I use so users can log in using what they typed?

w5m
  • 2,228
  • 3
  • 32
  • 44
user2169832
  • 9
  • 1
  • 2

2 Answers2

3

sha1 is a hashing algorithm, not a 2-way encryption. You cannot retrieve the original password.

  1. Hash the submitted password using the same algorithm.
  2. Fetch, from your database, the password hash for the user in question.
  3. Compare the two hashes. If they match, the credentials are OK.

Quentin
  • 857,932
  • 118
  • 1,152
  • 1,264
0

You should use crypt for password hashing, sha1/md5 are too weak.

All you need:

function check_password($password) {  
    ...//get db password to compare
    if (crypt($post_password, $db_results[0]['password']) == $db_results[0]['password']) {  
        return true;  
    } else { return false; }
}
Brock Hensley
  • 3,569
  • 2
  • 26
  • 45