Question

Probably I am missing something here.

Got an Express server with MongoDB and i'm using passport to authenticate. I'm using one of the standard code example to signup and it seems ok, but I can see the password I type in the password field (plain text) in my DB.
I expected it to be encrypted...

Am i doing something wrong?

Was it helpful?

Solution

You have to hash the password yourself. Here is how to do it using brcypt:

function hashPassword (password) {
    return bcrypt.hashSync(password, bcrypt.genSaltSync());
}

So before you save your user to the DB simply invoke that function like so:

 user.password = hashPassword(thepassword);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top