bCrypt的javadoc有如何加密密码的代码:
String pw_hash = BCrypt.hashpw(plain_password, BCrypt.gensalt());
Run Code Online (Sandbox Code Playgroud)
要检查明文密码是否与先前已经散列的密码匹配,请使用checkpw方法:
if (BCrypt.checkpw(candidate_password, stored_hash))
System.out.println("It matches");
else
System.out.println("It does not match");
Run Code Online (Sandbox Code Playgroud)
这些代码片段向我暗示随机生成的盐被丢弃.是这种情况,还是只是一个误导性的代码片段?
正如bcrypt 文档所述,为了将哈希值与纯文本进行比较,我们必须实现compare如下函数:
bcrypt.compare(myPlaintextPassword, hash).then(function(result) { //do stuff });
Run Code Online (Sandbox Code Playgroud)
但似乎没有办法告诉函数盐腌的轮次。函数如何获取该数字?