How does node.bcrypt.js compare hashed and plaintext passwords without the salt?

前端 未结 6 1947
刺人心
刺人心 2020-12-07 19:45

From github:

To hash a password:

var bcrypt = require(\'bcrypt\');
bcrypt.genSalt(10, function(err, salt) {
    bcrypt.hash(\"B4c0/\\/\", salt, funct         


        
6条回答
  •  刺人心
    刺人心 (楼主)
    2020-12-07 20:30

    Because I had the same question myself, I know exactly what you are thinking about.

    You have a misconception between "Secret Key" which is used in Cryptographic algorithms and "Salt" which is used to slow down the encryption process and make it harder for hackers to use brute force.

    When you use the plain password and the salt to generate the hash, this hash uses as secret key the password itself! So the next time you will try to compare it with a plain password, this plain password must be the exact same one you used to generate the hash! So this is why you don't have to store it somewhere else because it is always provided by the user on both register and login steps!

提交回复
热议问题