Node.js hashing of passwords

前端 未结 6 571
小鲜肉
小鲜肉 2021-01-29 23:25

I am currently using the following for hashing passwords:

var pass_shasum = crypto.createHash(\'sha256\').update(req.body.password).digest(\'hex\');
6条回答
  •  悲&欢浪女
    2021-01-30 00:03

    bcrypt also can be called synchronously. Sample Coffeescript:

    bcrypt = require('bcrypt')
    
    encryptionUtil = 
        encryptPassword: (password, salt) ->
            salt ?= bcrypt.genSaltSync()
            encryptedPassword = bcrypt.hashSync(password, salt)
            {salt, encryptedPassword}
    
        comparePassword: (password, salt, encryptedPasswordToCompareTo) ->
            {encryptedPassword} = @encryptPassword(password, salt)
            encryptedPassword == encryptedPasswordToCompareTo
    
    module.exports = encryptionUtil
    

提交回复
热议问题