From 69a1b3bf45738f048361ee4ccb6bdc64fce35720 Mon Sep 17 00:00:00 2001
From: MrShi <1878285526@qq.com>
Date: 星期三, 12 三月 2025 11:31:46 +0800
Subject: [PATCH] 更新

---
 server/system_service/src/main/java/com/doumee/core/utils/PwdCheckUtil.java |   78 +++++++++++++++++++++++++++++++++++++++
 1 files changed, 78 insertions(+), 0 deletions(-)

diff --git a/server/system_service/src/main/java/com/doumee/core/utils/PwdCheckUtil.java b/server/system_service/src/main/java/com/doumee/core/utils/PwdCheckUtil.java
new file mode 100644
index 0000000..e71f277
--- /dev/null
+++ b/server/system_service/src/main/java/com/doumee/core/utils/PwdCheckUtil.java
@@ -0,0 +1,78 @@
+package com.doumee.core.utils;
+
+import java.util.regex.Pattern;
+
+/**
+ * Java姝e垯鏍¢獙瀵嗙爜鑷冲皯鍖呭惈锛氬瓧姣嶆暟瀛楃壒娈婄鍙蜂腑鐨�2绉�
+ */
+public class PwdCheckUtil {
+
+    /**
+     * 鍋囧畾璁剧疆瀵嗙爜鏃讹紝瀵嗙爜瑙勫垯涓猴細  瀛楁瘝銆佹暟瀛椼�佺壒娈婄鍙凤紝鑷冲皯鍖归厤2绉�
+     * 鍒欏瘑鐮佸彲鑳藉嚭鐜扮殑鎯呭喌鏈夛細
+     * 1銆佹暟瀛�+鐗规畩绗﹀彿
+     * 2銆佸瓧姣�+鐗规畩绗﹀彿
+     * 3銆佸瓧姣�+鏁板瓧
+     * 4銆佸瓧姣�+鏁板瓧+鐗规畩绗﹀彿
+     * (缁勫悎涓庨『搴忔棤鍏�)
+     * 瑙e喅鎬濊矾锛�
+     * 1銆侀亶鍘嗗瓧绗︿覆鐨勫瓧绗︽暟缁勶紝鏌ョ湅鏄惁鍖呭惈鐩爣鐗规畩瀛楃锛岃嫢鍖呭惈锛屽垯鏍囪瀛楃涓�
+     * 鍖呭惈鐗规畩瀛楃锛屽苟鏇挎崲褰撳墠鐗规畩瀛楃涓�''銆�
+     * 2銆佸垽鏂墿涓嬬殑瀛楃缁勬垚鐨勫瓧绗︿覆锛屾槸鍚﹀尮閰嶄互涓嬫儏鍐�
+     * - 绾瓧姣�
+     * - 绾暟瀛�
+     * - 瀛楁瘝+鏁板瓧
+     * 3銆佸瓧绗︿覆鍖归厤瑙勫垯
+     * 绾瓧姣�+鍖呭惈鐗规畩瀛楃  ---- 鍖归厤閫氳繃
+     * 绾暟瀛�+鍖呭惈鐗规畩瀛楃 ---- 鍖归厤閫氳繃
+     * 瀛楁瘝+鏁板瓧+鍖呭惈涓暟瀛楃 ---- 鍖归厤閫氳繃
+     */
+    //鐗规畩瀛楃
+    public static final String SPEC_CHARACTERS = " !\"#$%&'()*+,-./:;<=>?@\\]\\[^_`{|}~";
+    // 绾瓧姣�
+    public static final String character = "[a-zA-Z]{1,}$";
+    // 绾暟瀛�
+    public static final String numberic = "[0-9]{1,}$";
+    // 瀛楁瘝鍜屾暟瀛�
+    public static final String number_and_character = "((^[a-zA-Z]{1,}[0-9]{1,}[a-zA-Z0-9]*)+)" +
+            "|((^[0-9]{1,}[a-zA-Z]{1,}[a-zA-Z0-9]*)+)$";
+    // 瀛楁瘝鎴栨暟瀛�
+    public static final String number_or_character = "[a-zA-Z0-9]+$";
+    // 瀛楁瘝鏁板瓧涓嬪垝绾�
+    public static final String ncw = "\\w+$";
+
+    public static boolean checkPassword(String targetString) {
+        String opStr = targetString;
+        boolean isLegal = false;
+        boolean hasSpecChar = false;
+        char[] charArray = opStr.toCharArray();
+        for (char c : charArray) {
+            if (SPEC_CHARACTERS.contains(String.valueOf(c))) {
+                hasSpecChar = true;
+                // 鏇挎崲姝ゅ瓧绗︿覆
+                opStr = opStr.replace(c, ' ');
+            }
+        }
+        String excSpecCharStr = opStr.replace(" ", "");
+        boolean isPureNum = Pattern.compile(numberic).matcher(excSpecCharStr).matches();
+        boolean isPureChar = Pattern.compile(character).matcher(excSpecCharStr).matches();
+        boolean isNumAndChar = Pattern.compile(number_and_character).matcher(excSpecCharStr).matches();
+        isLegal = ((isPureNum && hasSpecChar)
+                || (isPureChar && hasSpecChar) || isNumAndChar && hasSpecChar) || isNumAndChar;
+        System.out.println("瀛楃涓诧細" + targetString + ",鏄惁绗﹀悎瑙勫垯锛�" + isLegal);
+        System.out.println("---------------");
+        return isLegal;
+    }
+
+    public static void main(String[] args) {
+        checkPassword("123456a");
+//        checkPassword("41234123");
+//        checkPassword("#$%^&&*(");
+//        checkPassword("fasd$$");
+//        checkPassword("41234%%%");
+//        checkPassword("fasd41^(324");
+//        checkPassword("fa413%^&*");
+//        checkPassword("&%fa413%^&*");
+    }
+
+}
\ No newline at end of file

--
Gitblit v1.9.3