min = 4; # password_hash + PASSWORD_BCRYPT limit # https://www.php.net/manual/en/function.password-hash.php $this->max = 72; return $params; } /** * @param bool $noSpaces * @return bool */ public function setNoSpaces(bool $noSpaces = true): bool { $this->noSpaces = $noSpaces; return true; } /** * @param bool $noTags * @return bool */ public function setNoTags(bool $noTags = true): bool { $this->noTags = $noTags; return true; } /** * @param bool $noUrl * @return bool */ public function setNoUrl(bool $noUrl = true): bool { $this->noUrl = $noUrl; return true; } public function check(&$value) { if (! is_string($value) || $value === '') { return false; } $length = mb_strlen($value); if ($this->max !== false && $length > $this->max) { $this->replace['max'] = tpl::declension($this->max, _t('', 'symbol;symbols;symbols')); $this->setMessage(_t('error', 'The [attribute] must be [max] or less'), false); return false; } if ($this->min !== false && $length < $this->min) { $this->replace['min'] = tpl::declension($this->min, _t('', 'symbol;symbols;symbols')); $this->setMessage(_t('error', 'The [attribute] must be [min] or more'), false); return false; } if ($this->noSpaces && preg_match('/\s+/u', $value) > 0) { $this->setMessage(_t('error', 'The [attribute] must be without spaces')); return false; } if ( $this->noUrl && ( mb_stripos($value, 'www.') !== false || mb_stripos($value, 'http://') !== false || mb_stripos($value, 'https://') !== false ) || $this->noTags && ( $value !== strip_tags($value) ) ) { $this->setMessage(_t('error', 'The [attribute] has wrong format, try another password')); return false; } return true; } /** * Default message * @return string */ public function defaultMessage(): string { return _t('error', 'The [attribute] must be a valid password'); } }