我有一个哈希的Wordpress密码数据库。我试图根据数据库存储的密码检查用户的密码,但哈希值不正确。我在isMatch()
中使用this github code进行了一些登录。任何想法为什么这些密码不匹配?纯文本密码为alberta10
public boolean isMatch(String password, String storedHash) {
// The first 12 digits of the hash is used to modify the encryption.
String setting = storedHash.substring(0, 12);
logger.log(Level.INFO, "----Hashed pwd from db is: "+storedHash);
logger.log(Level.INFO, "----Hashed pwd using php-pass: "+encrypt(password, setting));
return storedHash.equals(encrypt(password, setting));
}
这是我的authenticate()
方法
private void authenticate(String username, String password) throws Exception {
// Throw an Exception if the credentials are invalid
PasswordHasher pwdHasher=new PasswordHasher();
_logger.log(Level.INFO, "----Authenticating user: "+username);
try{
Connection conn=authenticationBiz.connWordpressDB();
String query = "SELECT * FROM wp_users WHERE user_login = ?";
PreparedStatement preparedStmt = conn.prepareStatement(query);
preparedStmt.setString(1, username);
ResultSet rs=preparedStmt.executeQuery();
rs.next();//get first result
_logger.log(Level.INFO, "----Hashed pwd from db is: "+rs.getString("user_pass"));
if(pwdHasher.isMatch(password,rs.getString("user_pass")))
return;
}
catch(Exception e){
_logger.log(Level.INFO, "----Exception in Authenticating user: "+e);
throw e;
}
throw new Exception();
}
继承日志输出:
----Hashed pwd from db is: $P$BeatnTVG2/U8KZwpaWbPUF4yghHEKf.
17:21:40,997 INFO [com.mollom.phpass] (default task-37) ----Hashed pwd from db is: $P$BeatnTVG2/U8KZwpaWbPUF4yghHEKf.
----Hashed pwd using php-pass: $P$BeatnTVG2etvrth3rlCUdiNRm93PO9xZjXNr1f5s8izUZFfIq70V
答案 0 :(得分:2)
原来我使用的Github项目与用于生成哈希的初始标准不匹配。我发现:https://github.com/Wolf480pl/PHPass完美无缺
答案 1 :(得分:1)
Wordpress使用8次哈希迭代,你链接的git hub cod使用了15次迭代,也许你不能尝试减少常量HASH_ITERATIONS中定义的哈希迭代次数。