package password;
import java.security.MessageDigest;
import java.util.Objects;
* @description:
* @author: liu.w
* @create: 2020-08-25 11:21
**/
public class CheckPwd {
public static final String salt = "deal";
public static void main(String[] args) {
System.out.println(checkPW(1, "abcd", "b2674a9182edd9054bfb7029628e11fa"));
}
* @param userId
* @param password 原始密码
* @param secrets 加密的密码摘要
* @return
*/
public static boolean checkPW(Integer userId, String password, String secrets) {
String pwd = userId + password + salt;
return Objects.equals(secrets, encrypt(pwd));
}
public static String encrypt(String dataStr) {
try {
MessageDigest m = MessageDigest.getInstance("MD5");
m.update(dataStr.getBytes("UTF8"));
byte[] str = m.digest();
String result = "";
for (int i = 0; i < str.length; i++) {
result += Integer.toHexString((0x000000FF & str[i]) | 0xFFFFFF00).substring(6);
}
return result;
} catch (Exception e) {
e.printStackTrace();
}
return "";
}
}
评论