package com.crc.mam.admin.controller.system.demo;
import com.crc.mam.util.DigestUtils;
public class PasswordUtils {
public static void main(String[] args) {
String userId = "CYC";
String plainPassWord = "md5password";
String encryptionPassWord = getMD5(userId, plainPassWord);
boolean passwordMatch = checkPW(userId, plainPassWord, encryptionPassWord);
if (passwordMatch) {
System.out.println("Provided user password " + plainPassWord + " is correct.");
} else {
System.out.println("Provided user password is incorrect!");
}
}
private static boolean checkPW(String userId, String plainPassWord, String encryptionPassWord) {
String generatePassWord = getMD5(userId, plainPassWord);
return encryptionPassWord.equalsIgnoreCase(generatePassWord);
}
* 生成md5
*
* @param userId
* @return
*/
public static String getMD5(String userId, String password) {
String str = userId + password;
String md5 = DigestUtils.md5DigestAsHex(str.getBytes()).toUpperCase();
return md5;
}
}
评论