SALT and HASH password in nodejs w/ crypto

前端 未结 7 2237
野趣味
野趣味 2020-12-07 18:43

I am trying to figure out how to salt and hash a password in nodejs using the crypto module. I am able to create the hashed password doing this:

UserSchema.         


        
7条回答
  •  天涯浪人
    2020-12-07 19:19

    There are two major steps involved in this scenario

    1) Creating and Storing password

    Here you will have to do the following.

    • Take the user password
    • Generate a string of random chars (salt)
    • Combine the salt with the user entered password
    • Hash the combined string.
    • Store the hash and the salt in the database.

    2) Validating user password

    This step would be required to authenticate the user.

    • The user will enter the username/email and the password.

    • Fetch the hash and the salt based on the username entered

    • Combine the salt with the user password

    • Hash the combination with the same hashing algorithm.

    • Compare the result.

    This tutorial has a detailed explaination on how to do it with nodejs crypto. Exactly what you are looking for. Salt Hash passwords using NodeJS crypto

提交回复
热议问题