Added password required symbols check (#713)

* Added password required symbols check

* Update Validate.php
This commit is contained in:
Roman Kelesidis 2023-05-24 18:43:41 +07:00 committed by GitHub
commit 6e4c8a1b88
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 43 additions and 1 deletions

View file

@ -372,6 +372,15 @@ $bb_cfg['unique_ip'] = false; // Запретить регистрацию не
$bb_cfg['new_user_reg_restricted'] = false; // Ограничить регистрацию новых пользователей по времени по указанному ниже интервалу
$bb_cfg['new_user_reg_interval'] = [0, 1, 2, 3, 4, 5, 6, 7, 8, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23]; // Допустимые часы регистрации
$bb_cfg['reg_email_activation'] = true; // Требовать активацию учетной записи по email
$bb_cfg['password_symbols'] = [
// Требовать наличие символов в пароле
'nums' => true, // Цифры
'spec_symbols' => false, // Спец. символы
'letters' => [ // Буквы
'uppercase' => true, // Заглавные буквы
'lowercase' => true // Строчные буквы
]
];
// Email
$bb_cfg['emailer'] = [

View file

@ -1461,6 +1461,10 @@ $lang['CHOOSE_PASS'] = 'Field for the password must not be empty!';
$lang['CHOOSE_PASS_ERR'] = 'Entered passwords do not match';
$lang['CHOOSE_PASS_ERR_MIN'] = 'Your password must be at least %d characters';
$lang['CHOOSE_PASS_ERR_MAX'] = 'Your password must be no longer than $d characters';
$lang['CHOOSE_PASS_ERR_NUM'] = 'The password must contain at least one digit';
$lang['CHOOSE_PASS_ERR_LETTER'] = 'The password must contain at least one letter of the Latin alphabet';
$lang['CHOOSE_PASS_ERR_LETTER_UPPERCASE'] = 'The password must contain at least one uppercase letter of the Latin alphabet';
$lang['CHOOSE_PASS_ERR_SPEC_SYMBOL'] = 'The password must contain at least one special character';
$lang['CHOOSE_PASS_OK'] = 'Passwords match';
$lang['CHOOSE_PASS_REG_OK'] = 'Passwords match, you can proceed with the registration';
$lang['CHOOSE_PASS_FAILED'] = 'To change the password, you must correctly specify the current password';

View file

@ -16,6 +16,8 @@ use Egulias\EmailValidator\Validation\RFCValidation;
use Egulias\EmailValidator\Validation\MessageIDValidation;
use Egulias\EmailValidator\Validation\Extra\SpoofCheckValidation;
use TorrentPier\Helpers\IsHelper;
/**
* Class Validate
* @package TorrentPier
@ -168,7 +170,7 @@ class Validate
*/
public static function password(string $password, string $password_confirm)
{
global $lang;
global $lang, $bb_cfg;
// Check for empty
if (empty($password) || empty($password_confirm)) {
@ -188,6 +190,33 @@ class Validate
return sprintf($lang['CHOOSE_PASS_ERR_MIN'], PASSWORD_MIN_LENGTH);
}
// Symbols check
if ($bb_cfg['password_symbols']) {
// Numbers
if ($bb_cfg['password_symbols']['nums']) {
if (!IsHelper::isContainsNums($password)) {
return $lang['CHOOSE_PASS_ERR_NUM'];
}
}
// Letters
if ($bb_cfg['password_symbols']['letters']['lowercase']) {
if (!IsHelper::isContainsLetters($password)) {
return $lang['CHOOSE_PASS_ERR_LETTER'];
}
}
if ($bb_cfg['password_symbols']['letters']['uppercase']) {
if (!IsHelper::isContainsLetters($password, true)) {
return $lang['CHOOSE_PASS_ERR_LETTER_UPPERCASE'];
}
}
// Spec symbols
if ($bb_cfg['password_symbols']['spec_symbols']) {
if (!IsHelper::isContainsSpecSymbols($password)) {
return $lang['CHOOSE_PASS_ERR_SPEC_SYMBOL'];
}
}
}
return false;
}
}