mirror of
https://github.com/torrentpier/torrentpier
synced 2025-08-20 13:24:01 -07:00
Added password method in validator (#625)
Метод который занимается валидацией пароля, в будущем будет дополнен ещё несколькими проверками при необходимости (наличие цифр, букв, спец-символом)
This commit is contained in:
parent
aa9d02d41f
commit
edc57bfd2a
3 changed files with 41 additions and 20 deletions
|
@ -40,22 +40,13 @@ switch ($mode) {
|
||||||
case 'check_pass':
|
case 'check_pass':
|
||||||
$pass = (string)$this->request['pass'];
|
$pass = (string)$this->request['pass'];
|
||||||
$pass_confirm = (string)$this->request['pass_confirm'];
|
$pass_confirm = (string)$this->request['pass_confirm'];
|
||||||
if (empty($pass) || empty($pass_confirm)) {
|
|
||||||
$html = '<img src="./styles/images/bad.gif"> <span class="leechmed bold">' . $lang['CHOOSE_PASS'] . '</span>';
|
if ($err = \TorrentPier\Legacy\Validate::password($pass, $pass_confirm)) {
|
||||||
} else {
|
$html = '<img src="./styles/images/bad.gif"> <span class="leechmed bold">' . $err . '</span>';
|
||||||
if ($pass != $pass_confirm) {
|
|
||||||
$html = '<img src="./styles/images/bad.gif"> <span class="leechmed bold">' . $lang['CHOOSE_PASS_ERR'] . '</span>';
|
|
||||||
} else {
|
|
||||||
if (mb_strlen($pass, 'UTF-8') > 20) {
|
|
||||||
$html = '<img src="./styles/images/bad.gif"> <span class="leechmed bold">' . sprintf($lang['CHOOSE_PASS_ERR_MAX'], 20) . '</span>';
|
|
||||||
} elseif (mb_strlen($pass, 'UTF-8') < 5) {
|
|
||||||
$html = '<img src="./styles/images/bad.gif"> <span class="leechmed bold">' . sprintf($lang['CHOOSE_PASS_ERR_MIN'], 5) . '</span>';
|
|
||||||
} else {
|
} else {
|
||||||
$text = (IS_GUEST) ? $lang['CHOOSE_PASS_REG_OK'] : $lang['CHOOSE_PASS_OK'];
|
$text = (IS_GUEST) ? $lang['CHOOSE_PASS_REG_OK'] : $lang['CHOOSE_PASS_OK'];
|
||||||
$html = '<img src="./styles/images/good.gif"> <span class="seedmed bold">' . $text . '</span>';
|
$html = '<img src="./styles/images/good.gif"> <span class="seedmed bold">' . $text . '</span>';
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -204,13 +204,10 @@ foreach ($profile_fields as $field => $can_edit) {
|
||||||
|
|
||||||
// пароль для гостя и при смене пароля юзером
|
// пароль для гостя и при смене пароля юзером
|
||||||
if (!empty($new_pass)) {
|
if (!empty($new_pass)) {
|
||||||
if (mb_strlen($new_pass, 'UTF-8') > 20) {
|
if ($err = \TorrentPier\Legacy\Validate::password($new_pass, $cfm_pass)) {
|
||||||
$errors[] = sprintf($lang['CHOOSE_PASS_ERR_MAX'], 20);
|
$errors[] = $err;
|
||||||
} elseif (mb_strlen($new_pass, 'UTF-8') < 4) {
|
|
||||||
$errors[] = sprintf($lang['CHOOSE_PASS_ERR_MIN'], 4);
|
|
||||||
} elseif ($new_pass != $cfm_pass) {
|
|
||||||
$errors[] = $lang['CHOOSE_PASS_ERR'];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$db_data['user_password'] = md5(md5($new_pass));
|
$db_data['user_password'] = md5(md5($new_pass));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -143,4 +143,37 @@ class Validate
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Validate user entered password
|
||||||
|
*
|
||||||
|
* @param string $password
|
||||||
|
* @param string $password_confirm
|
||||||
|
*
|
||||||
|
* @return bool|string
|
||||||
|
*/
|
||||||
|
public static function password(string $password, string $password_confirm)
|
||||||
|
{
|
||||||
|
global $lang;
|
||||||
|
|
||||||
|
// Check for empty
|
||||||
|
if (empty($pass) || empty($pass_confirm)) {
|
||||||
|
return $lang['CHOOSE_PASS'];
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check password confirm
|
||||||
|
if ($password_confirm != $password) {
|
||||||
|
return $lang['CHOOSE_PASS_ERR'];
|
||||||
|
}
|
||||||
|
|
||||||
|
// Length
|
||||||
|
if (mb_strlen($password, 'UTF-8') > PASSWORD_MAX_LENGTH) {
|
||||||
|
return sprintf($lang['CHOOSE_PASS_ERR_MAX'], PASSWORD_MAX_LENGTH);
|
||||||
|
}
|
||||||
|
if (mb_strlen($password, 'UTF-8') < PASSWORD_MIN_LENGTH) {
|
||||||
|
return sprintf($lang['CHOOSE_PASS_ERR_MIN'], PASSWORD_MIN_LENGTH);
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue