+ zin: add password widget.

This commit is contained in:
liugang
2023-07-27 10:14:13 +08:00
parent 4406e82765
commit 210ae39de2
3 changed files with 108 additions and 0 deletions
+8
View File
@@ -1689,3 +1689,11 @@ function tableChart(): tableChart
{
return createWg('tableChart', func_get_args());
}
/**
* Password widget.
*/
function password(): password
{
return createWg('password', func_get_args());
}
+51
View File
@@ -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;
}
+49
View File
@@ -0,0 +1,49 @@
<?php
declare(strict_types=1);
namespace zin;
class password extends wg
{
protected static array $defineProps = array(
'id?: string="password1"',
'name?: string="password1"',
'strengthID?: string="passwordStrength"'
);
public static function getPageJS(): string|false
{
return file_get_contents(__DIR__ . DS . 'js' . DS . 'v1.js');
}
protected function build(): array
{
global $app, $config, $lang;
$app->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')
)
)
);
}
}