feat: 登录密码改用 BCrypt 校验

This commit is contained in:
2026-06-18 00:06:42 +08:00
parent d0c78ceb28
commit 2cf3533141
4 changed files with 41 additions and 7 deletions
@@ -0,0 +1,24 @@
package com.guo.learningprogresstracker.utils;
import org.junit.jupiter.api.Test;
import org.mindrot.jbcrypt.BCrypt;
import static org.junit.jupiter.api.Assertions.assertTrue;
class BCryptPasswordGeneratorTest {
@Test
void generatePasswordHash() {
String password = System.getProperty("password", "admin");
int rounds = Integer.parseInt(System.getProperty("rounds", "10"));
String hash = BCrypt.hashpw(password, BCrypt.gensalt(rounds));
System.out.println("BCrypt hash:");
System.out.println(hash);
System.out.println("SQL:");
System.out.printf("UPDATE `user` SET `user_password` = '%s' WHERE `user_name` = 'admin';%n", hash);
assertTrue(BCrypt.checkpw(password, hash));
}
}