如何使用jBCrypt比较来自2个servlet的散列密码

时间:2018-04-23 09:55:24

标签: java jbcrypt

我在如何以及在哪里上遇到问题,比较我在注册servlet上加密的密码和我在登录时加密的密码。的servlet。

希望你们能帮助我。谢谢。 登录servlet:

String password = request.getParameter("pword");
String haspw = BCrypt.hashpw(password, salt);

/* if username and password match*/
UserIO io = new UserIO();

authenticate = io.LogAccount(username, haspw);
if (authenticate == true) {
    uri = "Homepage.jsp";
    session.setAttribute("active", username);
} else {
    uri = "/WEB-INF/jsp/error.jsp";
}
RequestDispatcher rd = request.getRequestDispatcher(uri);
rd.forward(request, response);
out.close();

UserIO

if (registered_name.isEmpty() ||registered_pass.isEmpty()) { //registered_name.equals(username) && registered_pass.equals(password)
    //uri = "Homepage.jsp";
    hasInfo = false;
} else if (registered_name.equals(username) && registered_pass.equals(password)) {
hasInfo = true;
}

注册Servlet

String pword = request.getParameter("pword");
    String hashed = BCrypt.hashpw(pword, salt);

1 个答案:

答案 0 :(得分:1)

使用方法checkpw

BCrypt.checkpw(pword, salt);

这会在比较中返回一个布尔值。