Quellcode durchsuchen

强密码判断

laiguoran vor 3 Jahren
Ursprung
Commit
0a0d247916
2 geänderte Dateien mit 7 neuen und 2 gelöschten Zeilen
  1. 7 1
      app/controller/setting_controller.js
  2. 0 1
      app/public/js/setting.js

+ 7 - 1
app/controller/setting_controller.js

@@ -476,6 +476,11 @@ module.exports = app => {
                 // 获取验证规则
                 const rule = ctx.service.projectAccount.rule('add');
                 ctx.validate(rule);
+                // 判断新密码的强度
+                const reg = /^(?![0-9]+$)(?![a-zA-Z]+$).{6,16}$/;
+                if (!reg.test(ctx.request.body.password)) {
+                    throw '请设置至少包含数字和字母的密码';
+                }
                 ctx.request.body.project_id = projectData.id;
                 const result = await ctx.service.projectAccount.save(ctx.request.body);
                 if (!result) {
@@ -486,6 +491,7 @@ module.exports = app => {
                 ctx.redirect('/' + ctx.controllerName + '/user');
             } catch (error) {
                 console.log(error);
+                ctx.session.postError = error.toString();
                 this.setMessage(error.toString(), this.messageType.ERROR);
                 ctx.redirect(ctx.request.header.referer);
             }
@@ -544,7 +550,7 @@ module.exports = app => {
                 // 判断新密码的强度
                 const reg = /^(?![0-9]+$)(?![a-zA-Z]+$).{6,16}$/;
                 if (!reg.test(password)) {
-                    throw '请设置至少包含数字和字母的密码';
+                    throw '请设置至少包含数字和字母的密码';
                 }
                 const result = await ctx.service.projectAccount.resetPassword(accountId, password, account);
                 if (!result) {

+ 0 - 1
app/public/js/setting.js

@@ -535,7 +535,6 @@ function randPassword() {
         'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'];
     const numRan = numberSeed[Math.floor((Math.random() * numberSeed.length))];
     const strRan = stringSeed[Math.floor((Math.random() * stringSeed.length))];
-    console.log(numRan, strRan);
     const randSeed = stringSeed.concat(numberSeed);
     const seedLength = randSeed.length - 1;
     for (let i = 0; i < length; i++) {