diff --git a/lib/zin/func.php b/lib/zin/func.php index 7fe5866774..4b0dcc27e8 100644 --- a/lib/zin/func.php +++ b/lib/zin/func.php @@ -1689,3 +1689,11 @@ function tableChart(): tableChart { return createWg('tableChart', func_get_args()); } + +/** + * Password widget. + */ +function password(): password +{ + return createWg('password', func_get_args()); +} diff --git a/lib/zin/wg/password/js/v1.js b/lib/zin/wg/password/js/v1.js new file mode 100644 index 0000000000..6b755abbf8 --- /dev/null +++ b/lib/zin/wg/password/js/v1.js @@ -0,0 +1,51 @@ +function checkPassword() +{ + const password = $(event.target).val(); + if(password == '') + { + $('#passwordStrength').html('').addClass('hidden'); + return false; + } + + const passwordStrength = passwordStrengthList[computePasswordStrength(password)]; + $('#passwordStrength').html(passwordStrength).removeClass('hidden'); +} + +function computePasswordStrength(password) +{ + if(password.length == 0) return 0; + + var strength = 0; + var length = password.length; + + var complexity = new Array(); + for(i = 0; i < length; i++) + { + letter = password.charAt(i); + var asc = letter.charCodeAt(); + if(asc >= 48 && asc <= 57) + { + complexity[0] = 1; + } + else if((asc >= 65 && asc <= 90)) + { + complexity[1] = 2; + } + else if(asc >= 97 && asc <= 122) + { + complexity[2] = 4; + } + else + { + complexity[3] = 8; + } + } + + var sumComplexity = 0; + for(i in complexity) sumComplexity += complexity[i]; + + if((sumComplexity == 7 || sumComplexity == 15) && password.length >= 6) strength = 1; + if(sumComplexity == 15 && password.length >= 10) strength = 2; + + return strength; +} diff --git a/lib/zin/wg/password/v1.php b/lib/zin/wg/password/v1.php new file mode 100644 index 0000000000..5136661129 --- /dev/null +++ b/lib/zin/wg/password/v1.php @@ -0,0 +1,49 @@ +loadLang('user'); + $jsRoot = $app->getWebRoot() . 'js/'; + + list($id, $name, $strengthID) = $this->prop(array('id', 'name', 'strengthID')); + + return array + ( + h::jsCall('$.getScript', $jsRoot . 'md5.js'), + jsVar('passwordStrengthList', $lang->user->passwordStrengthList), + inputGroup + ( + input + ( + setID($id), + on::keyup('checkPassword'), + set::type('password'), + set::name($name), + set::placeholder(zget($lang->user->placeholder->passwordStrength, $config->safe->mode, '')) + ), + span + ( + setID($strengthID), + setClass('input-group-addon hidden') + ) + ) + ); + } +}