| | |
| | | import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; |
| | | |
| | | public class PasswordTest { |
| | | public static void main(String[] args) { |
| | | BCryptPasswordEncoder encoder = new BCryptPasswordEncoder(); |
| | | String hashedPassword = "$2a$10$VBHNbQlhM1OnQ8QTLkEVSeXBfLAlD9AJqNjErsYC664SUzMZZxjp."; |
| | | String plainPassword = "123456"; |
| | | |
| | | boolean matches = encoder.matches(plainPassword, hashedPassword); |
| | | System.out.println("Password matches: " + matches); |
| | | |
| | | // 也测试一下新生成的密码 |
| | | String newHash = encoder.encode(plainPassword); |
| | | System.out.println("New hash: " + newHash); |
| | | System.out.println("New hash matches: " + encoder.matches(plainPassword, newHash)); |
| | | } |
| | | } |
| | | import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
|
| | |
|
| | | public class PasswordTest {
|
| | | public static void main(String[] args) {
|
| | | BCryptPasswordEncoder encoder = new BCryptPasswordEncoder();
|
| | | String hashedPassword = "$2a$10$VBHNbQlhM1OnQ8QTLkEVSeXBfLAlD9AJqNjErsYC664SUzMZZxjp.";
|
| | | String plainPassword = "123456";
|
| | | |
| | | boolean matches = encoder.matches(plainPassword, hashedPassword);
|
| | | System.out.println("Password matches: " + matches);
|
| | | |
| | | // 也测试一下新生成的密码
|
| | | String newHash = encoder.encode(plainPassword);
|
| | | System.out.println("New hash: " + newHash);
|
| | | System.out.println("New hash matches: " + encoder.matches(plainPassword, newHash));
|
| | | }
|
| | | }
|