Question

How to implement the django's password validation in ruby so that i can migrate my user database from old django application to a new ruby application ? (Q&A style, what I tried is actually detailled as an answer)

Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top