[Answered ]-How to replicate django's password validation in ruby?

2👍

The django application (at least the one I had to deal with) use pbkdf2 password hashing.

The details are explained in wikipedia, and I’ve just released a gem that implement it so that a validation method can be directly used:

require 'pbkdf2_password_hasher'
# Some hash from django 
hsh = 'pbkdf2_sha256$12000$PEnXGf9dviXF$2soDhu1WB8NSbFDm0w6NEe6OvslVXtiyf4VMiiy9rH0='

#check with right password:
Pbkdf2PasswordHasher::check_password('bite',hsh) #=> true

#check with wrong password:
Pbkdf2PasswordHasher::check_password('bitten',hsh) #=> false

Another gem pbkdf2-ruby also exists, however I had some trouble working with it with ruby 2.1.1 (don’t know about other versions) so I think this still might help.

👤aherve

Leave a comment