You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
33 lines
1.5 KiB
33 lines
1.5 KiB
|
1 month ago
|
import org.springframework.security.crypto.argon2.Argon2PasswordEncoder;
|
||
|
|
|
||
|
|
import java.sql.Connection;
|
||
|
|
import java.sql.DriverManager;
|
||
|
|
|
||
|
|
/**
|
||
|
|
* 将全部未删除员工的登录密码重置为 123456(Argon2id,与 SecurityPasswordService 一致)
|
||
|
|
*/
|
||
|
|
public class ResetAllEmployeePasswords {
|
||
|
|
private static final String URL =
|
||
|
|
"jdbc:kingbase8://8.162.3.203:54321/economic_crime_dev?currentSchema=public&clientEncoding=utf8&socketTimeout=30000&loginTimeout=30";
|
||
|
|
private static final String USER = "dcms_dev";
|
||
|
|
private static final String PASS = "sdy@2025#dc$ks";
|
||
|
|
private static final String PLAIN_PASSWORD = "123456";
|
||
|
|
|
||
|
|
public static void main(String[] args) throws Exception {
|
||
|
|
Class.forName("com.kingbase8.Driver");
|
||
|
|
Argon2PasswordEncoder encoder = Argon2PasswordEncoder.defaultsForSpringSecurity_v5_8();
|
||
|
|
String encrypted = encoder.encode(PLAIN_PASSWORD);
|
||
|
|
if (!encoder.matches(PLAIN_PASSWORD, encrypted)) {
|
||
|
|
throw new IllegalStateException("password hash self-check failed");
|
||
|
|
}
|
||
|
|
|
||
|
|
try (Connection conn = DriverManager.getConnection(URL, USER, PASS);
|
||
|
|
var ps = conn.prepareStatement(
|
||
|
|
"UPDATE t_employee SET login_pwd = ?, update_time = NOW() WHERE deleted_flag = 0")) {
|
||
|
|
ps.setString(1, encrypted);
|
||
|
|
int updated = ps.executeUpdate();
|
||
|
|
System.out.println("Reset password to 123456 for " + updated + " employee(s).");
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|