Question

I'd like to export users from a system with django authenticaion to new system using passportjs/node. My guess is that I would have to configure passport to use the same kind of hashing in order to make this work.

From the django user manual: "By default, Django uses the PBKDF2 algorithm with a SHA256 hash"

If making the hashing methods match is the way, I have this question: How can I set passportjs hashing to match?

Was it helpful?

Solution

Passport just provides you with a "container" function in which you can perform your own hash validation howsoever you like.

http://passportjs.org/guide/configure/

As for hash, in your case you can use either one of these

http://nodejs.org/api/crypto.html#crypto_crypto_pbkdf2_password_salt_iterations_keylen_callback

https://github.com/cryptocoinjs/pbkdf2-sha256

So once you have the user object from the database, you can compare it to the hash generated from the password supplied and match it and return the user.

So it might look something like this:

passport.use(new LocalStrategy(
    function(username, password, done) {
        var user = db.getUser('username');
        var generated_hash = hash(password, user.password.salt);
        var stored_hash = user.password.hash;
        if(generated_hash === stored_hash) 
            done(null, user);
    }
));

(salt is in the password in Django, btw)

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