密码的Node.jsencryption

我目前使用以下encryption密码:

var pass_shasum = crypto.createHash('sha256').update(req.body.password).digest('hex'); 

你能否build议改进以使项目更安全?

我使用follwing代码来密码和散列密码。

 var bcrypt = require('bcrypt'); exports.cryptPassword = function(password, callback) { bcrypt.genSalt(10, function(err, salt) { if (err) return callback(err); bcrypt.hash(password, salt, function(err, hash) { return callback(err, hash); }); }); }; exports.comparePassword = function(plainPass, hashword, callback) { bcrypt.compare(plainPass, hashword, function(err, isPasswordMatch) { return err == null ? callback(null, isPasswordMatch) : callback(err); }); }; 

bcrypt也可以同步调用。 示例咖啡:

 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 

还有节点的bcrypt-nodejs模块。 https://github.com/shaneGirish/bcrypt-nodejs

以前我在这里已经提到了bcrypt模块,但是在win7 x64上遇到了问题。 另一方面,bcrypt-nodejs是纯粹的bcrypt的JS实现,根本没有任何依赖关系。