geo*_*per 8 javascript mysql password-protection bcrypt node.js
我使用nodejs bcrypt库来获得更好的密码保护.
我不确定我究竟该如何使用它,但到目前为止我得到了这个:
//A module containing this login function:
login: function(credentials,req,res) {
//"credentials" is containing email and password from login form
var query = 'SELECT password, email FROM users WHERE email = ? LIMIT 1';
client.query(query,[credentials.email], function(err, results) {
if (results[0]) {
//Compare passwords
if (bcrypt.compareSync(credentials.password, results[0].password)) {
//Set session data and redirect to restricted area
}
}
});
}
Run Code Online (Sandbox Code Playgroud)
我删除了示例中的所有错误处理,以便更容易阅读代码.
1.这工作,我能够登录和设置会话.但这就是它的全部吗?我错过了什么吗?
2.生成哈希时看起来就像密码前面有盐一样.我不得不在db中保存盐吗?
任何帮助赞赏
| 归档时间: |
|
| 查看次数: |
5271 次 |
| 最近记录: |