Ruby on Rails & Android
Compare password with MySQL ENCRYPTed password
How to compare two passwords, one encrypted with the MySQL ENCRYPT function, when the other one is clear ?
Here’s how to compare:
- Get the encrypted_password
- Get the not_encrypted_password
- Compare the passwords by encoding the not_encrypted_password using the two first characters of the encrypted_password as salt for the crypt method.
In Ruby language, this means coding something like this:
not_encrypted_password.crypt(encrypted_password[0,2]) == encrypted_password |
return true if passwords are maching. Youpi !
I did this article to never forget this… Hoping it would be helpful for someone else !
| Print article | This entry was posted by Alexandre Gherschon on December 16, 2009 at 2:07 PM, and is filed under Databases, MySQL, Ruby. Follow any responses to this post through RSS 2.0. You can leave a response or trackback from your own site. |