Parcourir la source

用户密码支持自定义配置规则

RuoYi il y a 4 ans
Parent
commit
8bf5140a72

+ 26 - 0
ruoyi-admin/src/main/resources/static/ruoyi/js/common.js

@@ -347,6 +347,32 @@ function calSumWidth(elements) {
     return width;
 }
 
+/** 密码规则范围验证 */
+function checkpwd(chrtype, password) {
+	if (chrtype == 1) {
+		if(!$.common.numValid(password)){
+			$.modal.alertWarning("密码只能为0-9数字");
+			return false;
+		}
+	} else if (chrtype == 2) {
+		if(!$.common.enValid(password)){
+			$.modal.alertWarning("密码只能为a-z和A-Z字母");
+			return false;
+		}
+	} else if (chrtype == 3) {
+		if(!$.common.enNumValid(password)){
+			$.modal.alertWarning("密码必须包含字母以及数字");
+			return false;
+		}
+	} else if (chrtype == 4) {
+		if(!$.common.charValid(password)){
+			$.modal.alertWarning("密码必须包含字母、数字、以及特殊符号-、_");
+			return false;
+		}
+	}
+	return true;
+}
+
 // 日志打印封装处理
 var log = {
     log: function(msg) {

+ 20 - 0
ruoyi-admin/src/main/resources/static/ruoyi/js/ry-ui.js

@@ -1582,6 +1582,26 @@ var table = {
             isMobile: function () {
                 return navigator.userAgent.match(/(Android|iPhone|SymbianOS|Windows Phone|iPad|iPod)/i);
             },
+            // 数字正则表达式,只能为0-9数字
+            numValid : function(text){
+        		var patten = new RegExp(/^[0-9]+$/);
+        		return patten.test(text);
+        	},
+        	// 英文正则表达式,只能为a-z和A-Z字母
+            enValid : function(text){
+        		var patten = new RegExp(/^[a-zA-Z]+$/);
+        		return patten.test(text);
+        	},
+        	// 英文、数字正则表达式,必须包含(字母,数字)
+        	enNumValid : function(text){
+        		var patten = new RegExp(/^(?=.*[a-zA-Z]+)(?=.*[0-9]+)[a-zA-Z0-9]+$/);
+        		return patten.test(text);
+        	},
+        	// 英文、数字、特殊字符正则表达式,必须包含(字母,数字,特殊字符-_)
+        	charValid : function(text){
+        		var patten = new RegExp(/^(?=.*[A-Za-z])(?=.*\d)(?=.*[-_])[A-Za-z\d-_]{6,}$/);
+        		return patten.test(text);
+        	},
         }
     });
 })(jQuery);

+ 4 - 2
ruoyi-admin/src/main/resources/templates/system/user/add.html

@@ -221,7 +221,9 @@
         });
         
         function submitHandler() {
-	        if ($.validate.form()) {
+        	var chrtype = [[${@config.getKey('sys.account.chrtype')}]];
+			var password = $("#password").val();
+	        if ($.validate.form() && checkpwd(chrtype, password)) {
 	        	var data = $("#form-user-add").serializeArray();
 	        	var status = $("input[id='status']").is(':checked') == true ? 0 : 1;
 	        	var roleIds = $.form.selectCheckeds("role");
@@ -233,7 +235,7 @@
 	        }
 	    }
          
-        /*用户管理-新增-选择部门树*/
+        /* 用户管理-新增-选择部门树 */
         function selectDeptTree() {
         	var treeId = $("#treeId").val();
         	var deptId = $.common.isEmpty(treeId) ? "100" : $("#treeId").val();

+ 1 - 1
ruoyi-admin/src/main/resources/templates/system/user/edit.html

@@ -200,7 +200,7 @@
 	        }
 	    }
 
-        /*用户管理-修改-选择部门树*/
+        /* 用户管理-修改-选择部门树 */
         function selectDeptTree() {
         	var deptId = $.common.isEmpty($("#treeId").val()) ? "100" : $("#treeId").val();
             var url = ctx + "system/dept/selectDeptTree/" + deptId;

+ 3 - 1
ruoyi-admin/src/main/resources/templates/system/user/profile/profile.html

@@ -283,7 +283,9 @@
 		});
 		
 		function submitChangPassword () {
-	        if ($.validate.form("form-user-resetPwd")) {
+			var chrtype = [[${@config.getKey('sys.account.chrtype')}]];
+			var password = $("#newPassword").val();
+	        if ($.validate.form("form-user-resetPwd") && checkpwd(chrtype, password)) {
 	        	$.operate.saveModal(ctx + "system/user/profile/resetPwd", $('#form-user-resetPwd').serialize());
 	        }
 	    }

+ 3 - 1
ruoyi-admin/src/main/resources/templates/system/user/profile/resetPwd.html

@@ -82,7 +82,9 @@
 		});
 		
 		function submitHandler() {
-	        if ($.validate.form()) {
+			var chrtype = [[${@config.getKey('sys.account.chrtype')}]];
+			var password = $("#newPassword").val();
+	        if ($.validate.form() && checkpwd(chrtype, password)) {
 	        	$.operate.save(ctx + "system/user/profile/resetPwd", $('#form-user-resetPwd').serialize());
 	        }
 	    }

+ 1 - 0
sql/ry_20200708.sql → sql/ry_20200803.sql

@@ -535,6 +535,7 @@ insert into sys_config values(1, '主框架页-默认皮肤样式名称',     's
 insert into sys_config values(2, '用户管理-账号初始密码',         'sys.user.initPassword',    '123456',        'Y', 'admin', '2018-03-16 11-33-00', 'ry', '2018-03-16 11-33-00', '初始化密码 123456');
 insert into sys_config values(3, '主框架页-侧边栏主题',           'sys.index.sideTheme',      'theme-dark',    'Y', 'admin', '2018-03-16 11-33-00', 'ry', '2018-03-16 11-33-00', '深黑主题theme-dark,浅色主题theme-light,深蓝主题theme-blue');
 insert into sys_config values(4, '账号自助-是否开启用户注册功能', 'sys.account.registerUser', 'false',         'Y', 'admin', '2018-03-16 11-33-00', 'ry', '2018-03-16 11-33-00', '是否开启注册用户功能');
+insert into sys_config values(5, '用户管理-密码字符范围',         'sys.account.chrtype',      '0',             'Y', 'admin', '2018-03-16 11-33-00', 'ry', '2018-03-16 11-33-00', '默认任意字符范围,0任意(密码可以输入任意字符),1数字(密码只能为0-9数字),2英文字母(密码只能为a-z和A-Z字母),3字母和数字(密码必须包含字母,数字),4字母数组和特殊字符(密码包含字母,数字,特殊字符-_)');
 
 
 -- ----------------------------