|
@@ -5,15 +5,17 @@ import java.util.Scanner;
|
|
import java.util.UUID;
|
|
import java.util.UUID;
|
|
|
|
|
|
public class UserInit {
|
|
public class UserInit {
|
|
- Scanner scan = new Scanner(System.in);
|
|
|
|
- String user_name;
|
|
|
|
- String password;
|
|
|
|
- String uuid;
|
|
|
|
- String [] UserData;
|
|
|
|
|
|
+ private Scanner scan = new Scanner(System.in);
|
|
|
|
+ private String user_name;
|
|
|
|
+ private String user_password;
|
|
|
|
+ private String uuid;
|
|
|
|
+ private String user_register_time;
|
|
|
|
+ private int user_permission_level;
|
|
|
|
+ private String[] UserData; // 将UserData数组定义为私有
|
|
|
|
|
|
public UserInit() {
|
|
public UserInit() {
|
|
- UserData = new String[3];
|
|
|
|
- //用户信息初始化
|
|
|
|
|
|
+ UserData = new String[5];
|
|
|
|
+ // 用户信息初始化
|
|
System.out.println("请输入用户名:");
|
|
System.out.println("请输入用户名:");
|
|
this.user_name = scan.nextLine();
|
|
this.user_name = scan.nextLine();
|
|
while (this.user_name.isEmpty()) {
|
|
while (this.user_name.isEmpty()) {
|
|
@@ -22,21 +24,28 @@ public class UserInit {
|
|
}
|
|
}
|
|
UserData[0] = this.user_name;
|
|
UserData[0] = this.user_name;
|
|
System.out.println("请输入密码:");
|
|
System.out.println("请输入密码:");
|
|
- this.password = scan.nextLine();
|
|
|
|
- while (!isStrongPassword(this.password)) {
|
|
|
|
- System.out.println("密码强度不够,请重新输入:");
|
|
|
|
- this.password = scan.nextLine();
|
|
|
|
|
|
+ this.user_password = scan.nextLine();
|
|
|
|
+ while (!isStrongPassword(this.user_password)) {
|
|
|
|
+ System.out.println("密码需为8位以上大小写字母和数字组合,请重新输入:");
|
|
|
|
+ this.user_password = scan.nextLine();
|
|
}
|
|
}
|
|
- UserData[1] = this.password;
|
|
|
|
|
|
+ UserData[1] = this.user_password;
|
|
this.uuid = UUID.randomUUID().toString(); // 使用标准的 UUID 生成方法
|
|
this.uuid = UUID.randomUUID().toString(); // 使用标准的 UUID 生成方法
|
|
UserData[2] = this.uuid;
|
|
UserData[2] = this.uuid;
|
|
- System.out.println("用户名:" + this.user_name + "\n密码:" + this.password + "\nuuid:" + this.uuid);
|
|
|
|
- System.out.println(Arrays.toString(UserData));
|
|
|
|
-
|
|
|
|
|
|
+ this.user_permission_level = 0;
|
|
|
|
+ UserData[3] = String.valueOf(this.user_permission_level);
|
|
|
|
+ this.user_register_time = String.valueOf(System.nanoTime());
|
|
|
|
+ UserData[4] = this.user_register_time;
|
|
|
|
+ System.out.println("用户名:" + this.user_name + "\n密码:" + this.user_password + "\nuuid:" + this.uuid + "\n注册时间:" + this.user_register_time);
|
|
|
|
+ System.out.println("UserData: " + Arrays.toString(UserData));
|
|
|
|
+ }
|
|
|
|
|
|
|
|
+ // 提供一个公共方法来获取UserData数组
|
|
|
|
+ public String[] getUserData() {
|
|
|
|
+ return UserData;
|
|
}
|
|
}
|
|
|
|
|
|
- private static final String PWD_REGEX = "^(?=.*[a-z])(?=.*[A-Z])(?=.*\\d)(?=.*[!@#$%^&*()=_+;':,.?]).{8,}$";
|
|
|
|
|
|
+ private static final String PWD_REGEX = "^(?=.*[a-z])(?=.*[A-Z])(?=.*\\d).{8,}$";
|
|
|
|
|
|
/**
|
|
/**
|
|
* 检测密码是否为强密码
|
|
* 检测密码是否为强密码
|
|
@@ -46,11 +55,13 @@ public class UserInit {
|
|
* @return 如果密码符合强密码的要求且不为空字符串,则返回true;否则返回false
|
|
* @return 如果密码符合强密码的要求且不为空字符串,则返回true;否则返回false
|
|
*/
|
|
*/
|
|
public static boolean isStrongPassword(String password) {
|
|
public static boolean isStrongPassword(String password) {
|
|
- //密码强度检测
|
|
|
|
|
|
+ // 密码强度检测
|
|
if (password == null || password.trim().isEmpty()) {
|
|
if (password == null || password.trim().isEmpty()) {
|
|
return false;
|
|
return false;
|
|
}
|
|
}
|
|
return password.matches(PWD_REGEX);
|
|
return password.matches(PWD_REGEX);
|
|
}
|
|
}
|
|
|
|
+
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+
|