|
@@ -0,0 +1,56 @@
|
|
|
+package org.snowchen.GreatSonServer.programinit;
|
|
|
+
|
|
|
+import java.util.Arrays;
|
|
|
+import java.util.Scanner;
|
|
|
+import java.util.UUID;
|
|
|
+
|
|
|
+public class UserInit {
|
|
|
+ Scanner scan = new Scanner(System.in);
|
|
|
+ String user_name;
|
|
|
+ String password;
|
|
|
+ String uuid;
|
|
|
+ String [] UserData;
|
|
|
+
|
|
|
+ public UserInit() {
|
|
|
+ UserData = new String[3];
|
|
|
+ //用户信息初始化
|
|
|
+ System.out.println("请输入用户名:");
|
|
|
+ this.user_name = scan.nextLine();
|
|
|
+ while (this.user_name.isEmpty()) {
|
|
|
+ System.out.println("用户名不能为空,请重新输入:");
|
|
|
+ this.user_name = scan.nextLine();
|
|
|
+ }
|
|
|
+ UserData[0] = this.user_name;
|
|
|
+ System.out.println("请输入密码:");
|
|
|
+ this.password = scan.nextLine();
|
|
|
+ while (!isStrongPassword(this.password)) {
|
|
|
+ System.out.println("密码强度不够,请重新输入:");
|
|
|
+ this.password = scan.nextLine();
|
|
|
+ }
|
|
|
+ UserData[1] = this.password;
|
|
|
+ this.uuid = UUID.randomUUID().toString(); // 使用标准的 UUID 生成方法
|
|
|
+ UserData[2] = this.uuid;
|
|
|
+ System.out.println("用户名:" + this.user_name + "\n密码:" + this.password + "\nuuid:" + this.uuid);
|
|
|
+ System.out.println(Arrays.toString(UserData));
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ private static final String PWD_REGEX = "^(?=.*[a-z])(?=.*[A-Z])(?=.*\\d)(?=.*[!@#$%^&*()=_+;':,.?]).{8,}$";
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 检测密码是否为强密码
|
|
|
+ * 强密码的定义基于预设的正则表达式PWD_REGEX,该表达式代表了密码的复杂性要求
|
|
|
+ *
|
|
|
+ * @param password 待检测的密码字符串
|
|
|
+ * @return 如果密码符合强密码的要求且不为空字符串,则返回true;否则返回false
|
|
|
+ */
|
|
|
+ public static boolean isStrongPassword(String password) {
|
|
|
+ //密码强度检测
|
|
|
+ if (password == null || password.trim().isEmpty()) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ return password.matches(PWD_REGEX);
|
|
|
+ }
|
|
|
+}
|
|
|
+
|