加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > Java > 正文

java – 尝试使用phpass检查wordpress密码哈希

发布时间:2020-12-15 01:08:08 所属栏目:Java 来源:网络整理
导读:我有一个散列的Wordpress密码数据库.我试图根据数据库存储密码检查用户的密码,但哈希值不正确.我正在使用this github code和一些登录isMatch().有什么想法为什么这些密码不匹配?纯文本密码是alberta10 public boolean isMatch(String password,String store

我有一个散列的Wordpress密码数据库.我试图根据数据库存储密码检查用户的密码,但哈希值不正确.我正在使用this github code和一些登录isMatch().有什么想法为什么这些密码不匹配?纯文本密码是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
最佳答案
事实证明我使用的Github项目与用于生成哈希的初始标准不匹配.我发现:https://github.com/Wolf480pl/PHPass完美无缺

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读