New file |
| | |
| | | package com.cl.util; |
| | | |
| | | import org.apache.commons.codec.digest.DigestUtils; |
| | | import org.mindrot.jbcrypt.BCrypt; |
| | | |
| | | public class BCryptPasswordEncoder { |
| | | |
| | | // 加密密码(自动生成盐值) |
| | | public static String encode(String rawPassword) { |
| | | return BCrypt.hashpw(rawPassword, BCrypt.gensalt()); |
| | | } |
| | | |
| | | // 验证密码 |
| | | public static boolean matches(String rawPassword, String encodedPassword) { |
| | | return BCrypt.checkpw(rawPassword, encodedPassword); |
| | | } |
| | | |
| | | public static void main(String[] args) { |
| | | BCryptPasswordEncoder encoder = new BCryptPasswordEncoder(); |
| | | String phone="19923261698"; |
| | | String encodePassword =encoder.encode(DigestUtils.md5Hex(phone.substring(phone.length() - 6))); |
| | | System.out.println(encodePassword); |
| | | System.out.println(DigestUtils.md5Hex("12345aA!")); |
| | | |
| | | System.out.println(encoder.matches(DigestUtils.md5Hex("261698"), encodePassword)); |
| | | } |
| | | } |