MD5 Encryption and password comparing

333 views Asked by At

I have created a password using MD5, then how to compare the encrypted password using MD5 with the password, which is given in login section in loopback ??

1

There are 1 answers

0
Sergey Romanovsky On

I assume you stored the hashed password (in your case it is hashed with MD5 function, but please use better hash like SHA-3):

$ echo mySecurePassword | md5
6b069a261eb584b5706a4a154fa8cdb1
$ echo 'user1:6b069a261eb584b5706a4a154fa8cdb1` >> /etc/my-password-storage

Now a user comes along, let's check if she knows the password:

$ login: user1
password: mysecurePassword
// here your 'login' program takes whatever user provided as a password and hashes it again:
// providedPasswordHash = md5("mysecurePassword") // providedPasswordHash = "a7d16ed9ff6f2185e4e5236e4cfcd3d1" now
// Now your program checks if it is the same as in /etc/my-password-storage for 'user1'
// Aah, it is not: a7d16ed9ff6f2185e4e5236e4cfcd3d1 != 6b069a261eb584b5706a4a154fa8cdb1
// The user forgot to uppercase S in their password
// so you prompt again:
login: user1
password: mySecurePassword
// now she typed correctly: md5(providedPassword)==md5HashStored, i.e. "6b069a261eb584b5706a4a154fa8cdb1"=="6b069a261eb584b5706a4a154fa8cdb1"
// she has successfully authenticated