在上学的时候,我被要求使用bcrypt正确存储密码(隐藏在数据库中)。比较它们时,该方法始终返回false。我的代码如下所示:
寄存器:
String username = editTextUsername.getText().toString();
String password = editTextPassword.getText().toString();
String hashedPW = BCrypt.hashpw(password, BCrypt.gensalt());
User user = new User(username, hashedPW);
user.save();
Run Code Online (Sandbox Code Playgroud)
登录:
String username = editTextUsername.getText().toString();
String enteredPassword = editTextPassword.getText().toString();
String hashedPW = BCrypt.hashpw(enteredPassword, BCrypt.gensalt());
User u = usercontroller.getUser(username); //gets user object
String password = u.getPassword;
BCrypt.checkpw(password, hashedPW); //always returns false
Run Code Online (Sandbox Code Playgroud)
我希望有BCrypt专业人士可以为我提供帮助。先感谢您!