diff --git a/library/config.php b/library/config.php index dd182e61d..9b4d95caf 100644 --- a/library/config.php +++ b/library/config.php @@ -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'] = [ diff --git a/library/language/source/main.php b/library/language/source/main.php index 6b2c99062..e18e04ec9 100644 --- a/library/language/source/main.php +++ b/library/language/source/main.php @@ -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'; diff --git a/src/Validate.php b/src/Validate.php index a398832d3..974a6ea2b 100644 --- a/src/Validate.php +++ b/src/Validate.php @@ -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; } }