diff --git a/src/main/java/com/ybw/mathapp/util/Register.java b/src/main/java/com/ybw/mathapp/util/Register.java index 1dad672..4ad06cd 100644 --- a/src/main/java/com/ybw/mathapp/util/Register.java +++ b/src/main/java/com/ybw/mathapp/util/Register.java @@ -16,26 +16,28 @@ public class Register { /** * 前端接口-密码格式验证 * @param password1 第一次输入的密码 - * @param password2 第二次输入的密码 * @return true表示符合要求,false表示不符合 */ - public static boolean isVaildPassword(String password1, String password2) { - if (password1 == null || password1.length() < 6 || password1.length() > 10) { - return false; - } - + public static boolean isVaildPassword(String password1) { // 使用正则表达式验证:长度6-10,只包含字母数字,且包含大小写字母和数字 String regex = "^(?=.*[a-z])(?=.*[A-Z])(?=.*\\d)[a-zA-Z\\d]{6,10}$"; if (!Pattern.matches(regex, password1)) { return false; } + return true; + } - System.out.print("请再次输入密码: "); + /** + * 前端接口-两次密码匹配 + * @param password1 第一次输入的密码 + * @param password2 第二次输入的密码 + * @return true表示符合要求,false表示不符合 + */ + public static boolean isEqualPassword(String password1, String password2) { if (!password1.equals(password2)) { System.out.println("两次输入的密码不一致!"); return false; } return true; } - }