From 7252dc6b7c7c047620c1c246532756164d74cddd Mon Sep 17 00:00:00 2001 From: liumengyi Date: Tue, 9 Aug 2022 14:51:15 +0800 Subject: [PATCH] * Finish task #63694. --- module/my/control.php | 6 ++-- module/my/css/changepassword.css | 1 + module/my/js/changepassword.js | 1 + module/my/js/editprofile.js | 1 + module/my/view/changepassword.html.php | 9 +++-- module/my/view/editprofile.html.php | 2 +- module/user/control.php | 10 +++--- module/user/css/common.css | 2 ++ module/user/css/reset.css | 1 + module/user/css/resetpassword.css | 1 + module/user/js/create.js | 3 +- module/user/js/edit.js | 3 +- module/user/js/reset.js | 25 +++++++++++--- module/user/js/resetpassword.js | 24 ++++++++++--- module/user/lang/zh-cn.php | 5 +++ module/user/model.php | 46 +++++++++++++++---------- module/user/view/create.html.php | 3 +- module/user/view/edit.html.php | 3 +- module/user/view/reset.html.php | 3 +- module/user/view/resetpassword.html.php | 5 ++- www/js/my.full.js | 22 ++++-------- 21 files changed, 114 insertions(+), 62 deletions(-) create mode 100644 module/my/css/changepassword.css diff --git a/module/my/control.php b/module/my/control.php index 68a32b6cf2..967ff2e724 100755 --- a/module/my/control.php +++ b/module/my/control.php @@ -1240,9 +1240,9 @@ EOF; if(!empty($_POST)) { $this->user->updatePassword($this->app->user->id); - if(dao::isError()) return print(js::error(dao::getError())); - if(isonlybody()) return print(js::closeModal('parent.parent', 'this')); - return print(js::locate($this->createLink('my', 'index'), 'parent.parent')); + if(dao::isError()) return $this->send(array('result' => 'fail', 'message' => dao::getError())); + if(isonlybody()) return $this->send(array('result' => 'success', 'message' => $this->lang->saveSuccess, 'closeModal' => true)); + return $this->send(array('result' => 'success', 'message' => $this->lang->saveSuccess,locate => $this->createLink('my', 'index'))); } $this->view->title = $this->lang->my->common . $this->lang->colon . $this->lang->my->changePassword; diff --git a/module/my/css/changepassword.css b/module/my/css/changepassword.css new file mode 100644 index 0000000000..994521df07 --- /dev/null +++ b/module/my/css/changepassword.css @@ -0,0 +1 @@ +#mainContent table > tbody > tr > td > div.text-danger.help-text {word-break: break-all;} diff --git a/module/my/js/changepassword.js b/module/my/js/changepassword.js index 97066b2dff..d3d6b0014a 100644 --- a/module/my/js/changepassword.js +++ b/module/my/js/changepassword.js @@ -14,6 +14,7 @@ $(document).ready(function() var password1 = $('input#password1').val().trim(); var passwordStrength = computePasswordStrength(password1); var rand = $('input#verifyRand').val(); + if(!password1Encrypted) $("#passwordLength").val(password1.length); if($("form input[name=passwordStrength]").length == 0) $('#submit').after(""); $("form input[name=passwordStrength]").val(passwordStrength); diff --git a/module/my/js/editprofile.js b/module/my/js/editprofile.js index 5e3fd65629..aa60cedfa6 100644 --- a/module/my/js/editprofile.js +++ b/module/my/js/editprofile.js @@ -13,6 +13,7 @@ $(document).ready(function() var password = $('input#verifyPassword').val(); var password1 = $('input#password1').val(); var passwordStrength = computePasswordStrength(password1); + if(!password1Encrypted) $("#passwordLength").val(password1.length); if($("form input[name=passwordStrength]").length == 0) $('#submit').after(""); $("form input[name=passwordStrength]").val(passwordStrength); diff --git a/module/my/view/changepassword.html.php b/module/my/view/changepassword.html.php index 4492c2a68f..42cd5db2e3 100755 --- a/module/my/view/changepassword.html.php +++ b/module/my/view/changepassword.html.php @@ -21,7 +21,7 @@

my->changePassword;?>

-
+ @@ -35,7 +35,7 @@ @@ -45,7 +45,10 @@ - +
user->account;?>user->newPassword;?> - safe->mode) ? $lang->user->placeholder->passwordStrength[$config->safe->mode] : '') . "'");?> + user->placeholder->passwordStrength, $config->safe->mode, '') . "'");?>
+ + +
app->user->modifyPasswordReason)):?> diff --git a/module/my/view/editprofile.html.php b/module/my/view/editprofile.html.php index 590aa9fbe1..45d197587a 100644 --- a/module/my/view/editprofile.html.php +++ b/module/my/view/editprofile.html.php @@ -84,7 +84,7 @@ user->getVisionList(), $user->visions, "class='form-control chosen' multiple");?> -
+
diff --git a/module/user/control.php b/module/user/control.php index e09326c219..e7f9f11abb 100755 --- a/module/user/control.php +++ b/module/user/control.php @@ -1068,15 +1068,14 @@ class user extends control if($_POST) { - if($needCreateFile) return print(js::reload('parent')); + if($needCreateFile) return $this->send(array('result' => 'success', 'locate' => 'reload')); $result = $this->user->resetPassword(); - if(dao::isError()) return print(js::error(dao::getError())); - if(!$result) return print(js::alert($this->lang->user->resetFail)); + if(dao::isError()) return $this->send(array('result' => 'fail', 'message' => dao::getError())); + if(!$result) return $this->send(array('result' => 'fail', 'message' => $this->lang->user->resetFail)); - echo js::alert($this->lang->user->resetSuccess); $referer = helper::safe64Encode($this->createLink('index', 'index')); - return print(js::locate(inlink('logout', 'referer=' . $referer), 'parent')); + return $this->send(array('result' => 'success', 'message' => $this->lang->user->resetSuccess, 'locate' => $this->createLink('user', 'logout', 'referer=' . $referer))); } /* Remove the real path for security reason. */ @@ -1174,6 +1173,7 @@ class user extends control $this->view->title = $this->lang->user->resetPWD; $this->view->expired = $expired; $this->view->user = empty($user) ? '' : $user; + $this->view->rand = $this->user->updateSessionRandom(); $this->display(); } diff --git a/module/user/css/common.css b/module/user/css/common.css index b55a793882..6a20da013c 100644 --- a/module/user/css/common.css +++ b/module/user/css/common.css @@ -3,3 +3,5 @@ .w-enVerifyPassword {width: 150px !important;} .c-id {width: 70px;} .c-hours {width: 110px;} + +#mainContent table > tbody > tr > td > div.text-danger.help-text {word-break: break-all;} diff --git a/module/user/css/reset.css b/module/user/css/reset.css index 788d51bfb7..775fe00af2 100644 --- a/module/user/css/reset.css +++ b/module/user/css/reset.css @@ -1,2 +1,3 @@ .alert-info > h5 > span {color: red;} .btn-back {margin-left: 25px;} +.table tbody > tr > td div.text-danger.help-text {word-break: break-all;} diff --git a/module/user/css/resetpassword.css b/module/user/css/resetpassword.css index 6a798688b0..1ee01498c6 100644 --- a/module/user/css/resetpassword.css +++ b/module/user/css/resetpassword.css @@ -13,3 +13,4 @@ body {background: #1183fb linear-gradient(-90deg, #0a48d1 0%, #1183fb 100%); bac #resetPanel .form-group .input-group.required:after {top: 6px;} #resetPanel .form-actions > .btn-wide {min-width: 45%;} #resetPanel .form-actions > a.btn-wide {margin-right: 0px;} +#resetForm .form-group div.text-danger.help-text {word-break: break-all;} diff --git a/module/user/js/create.js b/module/user/js/create.js index b8c30bacb3..32c6596e9a 100644 --- a/module/user/js/create.js +++ b/module/user/js/create.js @@ -92,11 +92,12 @@ $(function() $('#password2').change(function(){password2Encrypted = false}); $('#submit').click(function() { - if(!password1Encrypted && !password2Encrypted) + if(!password1Encrypted || !password2Encrypted) { var password1 = $('#password1').val(); var password2 = $('#password2').val(); var passwordStrength = computePasswordStrength(password1); + if(!password1Encrypted) $("#passwordLength").val(password1.length); if($("form input[name=passwordStrength]").length == 0) $('#submit').after(""); $("form input[name=passwordStrength]").val(passwordStrength); diff --git a/module/user/js/edit.js b/module/user/js/edit.js index 664049ff89..6b673efc4e 100644 --- a/module/user/js/edit.js +++ b/module/user/js/edit.js @@ -6,11 +6,12 @@ $(function() $('#password2').change(function(){password2Encrypted = false}); $('#submit').click(function() { - if(!password1Encrypted && !password2Encrypted) + if(!password1Encrypted || !password2Encrypted) { var password1 = $('#password1').val().trim(); var password2 = $('#password2').val().trim(); var passwordStrength = computePasswordStrength(password1); + if(!password1Encrypted) $("#passwordLength").val(password1.length); if($("form input[name=passwordStrength]").length == 0) $('#submit').after(""); $("form input[name=passwordStrength]").val(passwordStrength); diff --git a/module/user/js/reset.js b/module/user/js/reset.js index 2a28fa0a50..ccf8593186 100644 --- a/module/user/js/reset.js +++ b/module/user/js/reset.js @@ -1,10 +1,27 @@ $(document).ready(function() { + var password1Encrypted = false + var password2Encrypted = false + $('#password1').change(function(){password1Encrypted = false}); + $('#password2').change(function(){password2Encrypted = false}); $('form #submit').click(function() { - var password = $('#password1').val().trim(); - var passwordStrength = computePasswordStrength(password); + if(!password1Encrypted || !password2Encrypted) + { + var password1 = $('#password1').val().trim(); + var password2 = $('#password2').val().trim(); + var passwordStrength = computePasswordStrength(password1); - $('form').prepend(""); - }); + if($("form input[name=passwordStrength]").length == 0) $('#submit').after(""); + $("form input[name=passwordStrength]").val(passwordStrength); + + var rand = $('input#verifyRand').val(); + if(password1 && !password1Encrypted) $('#password1').val(md5(password1) + rand); + if(password2 && !password2Encrypted) $('#password2').val(md5(password2) + rand); + password1Encrypted = true; + password2Encrypted = true; + $('form').prepend(""); + $('form').prepend(""); + } + }) }); diff --git a/module/user/js/resetpassword.js b/module/user/js/resetpassword.js index f691afa07c..9f328f6445 100644 --- a/module/user/js/resetpassword.js +++ b/module/user/js/resetpassword.js @@ -10,13 +10,27 @@ $(function() }, 1000); } - $('#password1').attr('id', 'password'); - + var password1Encrypted = false + var password2Encrypted = false + $('#password1').change(function(){password1Encrypted = false}); + $('#password2').change(function(){password2Encrypted = false}); $('#submit').click(function() { - var password1 = $('#password').val(); - var passwordStrength = computePasswordStrength(password1); + if(!password1Encrypted || !password2Encrypted) + { + var password1 = $('#password1').val().trim(); + var password2 = $('#password2').val().trim(); + var passwordStrength = computePasswordStrength(password1); + if(!password1Encrypted) $("#passwordLength").val(password1.length); - $("form input[id=passwordStrength]").val(passwordStrength); + if($("form input[name=passwordStrength]").length == 0) $('#submit').after(""); + $("form input[name=passwordStrength]").val(passwordStrength); + + var rand = $('input#verifyRand').val(); + if(password1 && !password1Encrypted) $('#password1').val(md5(password1) + rand); + if(password2 && !password2Encrypted) $('#password2').val(md5(password2) + rand); + password1Encrypted = true; + password2Encrypted = true; + } }) }) diff --git a/module/user/lang/zh-cn.php b/module/user/lang/zh-cn.php index 37cafcb434..e9c36d5704 100644 --- a/module/user/lang/zh-cn.php +++ b/module/user/lang/zh-cn.php @@ -224,9 +224,14 @@ $lang->user->placeholder->loginAccount = '请输入用户名'; $lang->user->placeholder->loginUrl = '请输入禅道系统网址'; $lang->user->placeholder->email = '请输入邮箱'; +$lang->user->placeholder->passwordStrength[0] = '密码必须6位以上。'; $lang->user->placeholder->passwordStrength[1] = '6位以上,包含大小写字母,数字。'; $lang->user->placeholder->passwordStrength[2] = '10位以上,包含大小写字母,数字,特殊字符。'; +$lang->user->placeholder->passwordStrengthCheck[0] = '密码须6位以上。'; +$lang->user->placeholder->passwordStrengthCheck[1] = '密码必须6位以上,且包含大小写字母、数字。'; +$lang->user->placeholder->passwordStrengthCheck[2] = '密码必须10位以上,且包含大小写字母、数字、特殊符号。'; + $lang->user->error = new stdclass(); $lang->user->error->account = "【ID %s】的用户名应该为:三位以上的英文、数字或下划线的组合"; $lang->user->error->accountDupl = "【ID %s】的用户名已经存在"; diff --git a/module/user/model.php b/module/user/model.php index 404f016840..1c3a52e163 100644 --- a/module/user/model.php +++ b/module/user/model.php @@ -320,7 +320,7 @@ class userModel extends model ->setIF($this->post->password1 == false, 'password', '') ->setIF($this->post->email != false, 'email', trim($this->post->email)) ->join('visions', ',') - ->remove('new, group, password1, password2, verifyPassword, passwordStrength') + ->remove('new, group, password1, password2, verifyPassword, passwordStrength,passwordLength') ->get(); if(empty($_POST['verifyPassword']) or $this->post->verifyPassword != md5($this->app->user->password . $this->session->rand)) @@ -544,7 +544,7 @@ class userModel extends model ->setIF($this->post->password1 != false, 'password', substr($this->post->password1, 0, 32)) ->setIF($this->post->email != false, 'email', trim($this->post->email)) ->join('visions', ',') - ->remove('new, password1, password2, groups,verifyPassword, passwordStrength') + ->remove('new, password1, password2, groups,verifyPassword, passwordStrength,passwordLength') ->get(); if(empty($_POST['verifyPassword']) or $this->post->verifyPassword != md5($this->app->user->password . $this->session->rand)) @@ -786,7 +786,7 @@ class userModel extends model $user = fixer::input('post') ->setIF($this->post->password1 != false, 'password', substr($this->post->password1, 0, 32)) - ->remove('account, password1, password2, originalPassword, passwordStrength') + ->remove('account, password1, password2, originalPassword, passwordStrength,passwordLength') ->get(); if(empty($_POST['originalPassword']) or $this->post->originalPassword != md5($this->app->user->password . $this->session->rand)) @@ -800,6 +800,7 @@ class userModel extends model $this->app->user->modifyPassword = false; if(!dao::isError()) { + if(!empty($this->app->user->modifyPasswordReason)) $this->app->user->modifyPasswordReason = ''; $this->loadModel('score')->create('user', 'changePassword', $this->computePasswordStrength($this->post->password1)); } } @@ -818,7 +819,7 @@ class userModel extends model $user = $this->getById($this->post->account); if(!$user) return false; - $password = md5($this->post->password1); + $password = substr($this->post->password1, 0, 32); $this->dao->update(TABLE_USER)->set('password')->eq($password)->autoCheck()->where('account')->eq($this->post->account)->exec(); return !dao::isError(); } @@ -833,17 +834,28 @@ class userModel extends model { $_POST['password1'] = trim($_POST['password1']); $_POST['password2'] = trim($_POST['password2']); - if(!$canNoPassword and empty($_POST['password1'])) dao::$errors['password'][] = sprintf($this->lang->error->notempty, $this->lang->user->password); + if(!$canNoPassword and empty($_POST['password1'])) dao::$errors['password1'][] = sprintf($this->lang->error->notempty, $this->lang->user->password); if($this->post->password1 != false) { - if($this->post->password1 != $this->post->password2) dao::$errors['password'][] = $this->lang->error->passwordsame; - if(!validater::checkReg($this->post->password1, '|(.){6,}|')) dao::$errors['password'][] = $this->lang->error->passwordrule; + if(isset($this->config->safe->mode) and ($this->post->passwordStrength < $this->config->safe->mode)) dao::$errors['password1'][] = zget($this->lang->user->placeholder->passwordStrengthCheck, $this->config->safe->mode, $this->lang->user->weakPassword); + + if(isset($_POST['passwordLength']) and $this->post->passwordLength < 6 and empty(dao::$errors['password1'])) dao::$errors['password1'][] = zget($this->lang->user->placeholder->passwordStrengthCheck, 0, $this->lang->user->weakPassword); + + if($this->post->password1 != $this->post->password2) dao::$errors['password1'][] = $this->lang->error->passwordsame; - if(isset($this->config->safe->mode) and ($this->post->passwordStrength < $this->config->safe->mode)) dao::$errors['password'] = zget($this->lang->user->placeholder->passwordStrength, $this->config->safe->mode, $this->lang->user->weakPassword); if(!empty($this->config->safe->changeWeak)) { if(!isset($this->config->safe->weak)) $this->app->loadConfig('admin'); - if(strpos(",{$this->config->safe->weak},", ",{$this->post->password1},") !== false) dao::$errors['password1'][] = sprintf($this->lang->user->errorWeak, $this->config->safe->weak); + + if(strpos(",{$this->config->safe->weak},", ",{$this->post->password1},") !== false) dao::$errors['password1'] = sprintf($this->lang->user->errorWeak, $this->config->safe->weak); + + $weaks = array(); + foreach(explode(',', $this->config->safe->weak) as $weak) + { + $weak = md5(trim($weak)); + $weaks[$weak] = $weak; + } + if(isset($weaks[substr($this->post->password1, 0, 32)])) dao::$errors['password1'] = sprintf($this->lang->user->errorWeak, $this->config->safe->weak); } } return !dao::isError(); @@ -1656,7 +1668,6 @@ class userModel extends model $strength = 0; $length = strlen($password); - $uniqueChars = ''; $complexity = array(); $chars = str_split($password); foreach($chars as $letter) @@ -1664,7 +1675,7 @@ class userModel extends model $asc = ord($letter); if($asc >= 48 && $asc <= 57) { - $complexity[2] = 2; + $complexity[0] = 1; } elseif($asc >= 65 && $asc <= 90) { @@ -1672,20 +1683,17 @@ class userModel extends model } elseif($asc >= 97 && $asc <= 122) { - $complexity[0] = 1; + $complexity[2] = 4; } else { - $complexity[3] = 3; + $complexity[3] = 8; } - if(strpos($uniqueChars, $letter) === false) $uniqueChars .= $letter; } - if(strlen($uniqueChars) > 4)$strength += strlen($uniqueChars) - 4; - $strength += array_sum($complexity) + (2 * (count($complexity) - 1)); - if($length < 6 and $strength >= 10) $strength = 9; + $sumComplexity = array_sum($complexity); - $strength = $strength > 29 ? 29 : $strength; - $strength = floor($strength / 10); + if(($sumComplexity == 7 or $sumComplexity == 15) and $length >= 6) $strength = 1; + if($sumComplexity == 15 and $length >= 10) $strength = 2; return $strength; } diff --git a/module/user/view/create.html.php b/module/user/view/create.html.php index 667e7aaf23..44f22cf2c7 100644 --- a/module/user/view/create.html.php +++ b/module/user/view/create.html.php @@ -13,7 +13,7 @@ -safe->mode)) $lang->user->placeholder->password1 = $lang->user->placeholder->passwordStrength[$config->safe->mode]?> +user->placeholder->password1 = zget($lang->user->placeholder->passwordStrength, $config->safe->mode, '');?> user->placeholder);?> 1; config->vision);?> + createLink('company', 'browse'), $lang->goback, '', "class='btn btn-wide'")?> diff --git a/module/user/view/edit.html.php b/module/user/view/edit.html.php index 21012bdcb5..8306b1f4c1 100644 --- a/module/user/view/edit.html.php +++ b/module/user/view/edit.html.php @@ -71,7 +71,7 @@ - safe->mode) ? $lang->user->placeholder->passwordStrength[$config->safe->mode] : '') . "'");?> + user->placeholder->passwordStrength, $config->safe->mode, '') . "'");?> @@ -117,6 +117,7 @@ + diff --git a/module/user/view/reset.html.php b/module/user/view/reset.html.php index dc180f7c6e..79189a990f 100644 --- a/module/user/view/reset.html.php +++ b/module/user/view/reset.html.php @@ -11,6 +11,7 @@ */ ?> +
@@ -34,7 +35,7 @@
user->resetPassword?>
-
+ diff --git a/module/user/view/resetpassword.html.php b/module/user/view/resetpassword.html.php index ef1bcdc341..7279f8dfb6 100644 --- a/module/user/view/resetpassword.html.php +++ b/module/user/view/resetpassword.html.php @@ -10,6 +10,7 @@ */ include '../../common/view/header.lite.html.php'; ?> + @@ -28,7 +29,7 @@ include '../../common/view/header.lite.html.php';
- user->placeholder->loginPassword}' onmouseup='checkPassword(this.value)' onkeyup='checkPassword(this.value)'");?> + user->placeholder->loginPassword, $config->safe->mode, '') . "' onmouseup='checkPassword(this.value)' onkeyup='checkPassword(this.value)'");?>
@@ -41,6 +42,7 @@ include '../../common/view/header.lite.html.php'; account); echo html::hidden('passwordStrength', ''); + echo html::hidden('passwordLength', 0); echo html::submitButton($lang->user->submit); echo html::a(inlink('login'), $lang->goback, '', 'class="btn btn-wide"'); ?> @@ -49,6 +51,7 @@ include '../../common/view/header.lite.html.php';
user->account?>
+
diff --git a/www/js/my.full.js b/www/js/my.full.js index 0482f92a3c..7d02f6e575 100644 --- a/www/js/my.full.js +++ b/www/js/my.full.js @@ -505,7 +505,6 @@ function computePasswordStrength(password) var strength = 0; var length = password.length; - var uniqueChars = ''; var complexity = new Array(); for(i = 0; i < length; i++) { @@ -513,7 +512,7 @@ function computePasswordStrength(password) var asc = letter.charCodeAt(); if(asc >= 48 && asc <= 57) { - complexity[2] = 2; + complexity[0] = 1; } else if((asc >= 65 && asc <= 90)) { @@ -521,28 +520,19 @@ function computePasswordStrength(password) } else if(asc >= 97 && asc <= 122) { - complexity[0] = 1; + complexity[2] = 4; } else { - complexity[3] = 3; + complexity[3] = 8; } - if(uniqueChars.indexOf(letter) == -1) uniqueChars += letter; } - if(uniqueChars.length > 4) strength += uniqueChars.length - 4; var sumComplexity = 0; - var complexitySize = 0; - for(i in complexity) - { - complexitySize += 1; - sumComplexity += complexity[i]; - } - strength += sumComplexity + (2 * (complexitySize - 1)); - if(length < 6 && strength >= 10) strength = 9; + for(i in complexity) sumComplexity += complexity[i]; - strength = strength > 29 ? 29 : strength; - strength = Math.floor(strength / 10); + if((sumComplexity == 7 || sumComplexity == 15) && password.length >= 6) strength = 1; + if(sumComplexity == 15 && password.length >= 10) strength = 2; return strength; }