密码验证算法
发布于: 2020 年 08 月 26 日
public class CheckPassword { public static String encrypt(String password,String userId){ password += userId; try { MessageDigest md5 = MessageDigest.getInstance("MD5"); md5.update(password.getBytes("UTF-8")); byte[] bys=md5.digest(); password = new String(bys); } catch (NoSuchAlgorithmException e) { e.printStackTrace(); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } return password; } public static boolean checkPW(String userId,String inputPwd,String encryptPwd) { inputPwd += userId; try { MessageDigest md5 = MessageDigest.getInstance("MD5"); md5.update(inputPwd.getBytes("UTF-8")); byte[] bys=md5.digest(); String lastPassword = new String(bys); if(encryptPwd.equals(lastPassword)) { return true; } } catch (UnsupportedEncodingException e) { e.printStackTrace(); } catch (NoSuchAlgorithmException e) { e.printStackTrace(); } return false; } public static void main(String[] args) { System.out.println(encrypt("qwerty12","1")); String userId = "1"; String password = "qwerty12"; String encryptPassword = "�\b*��M�OXE<�#x�"; System.out.println(checkPW(userId,password,encryptPassword)); }}
qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq1111111111111111111111111111111111122222222222222222222222222222222222222222222222
划线
评论
复制
发布于: 2020 年 08 月 26 日阅读数: 47
潜默闻雨
关注
还未添加个人签名 2018.11.23 加入
还未添加个人简介
评论 (1 条评论)