Пример #1
0
 /**
  * @param PasswordOptions $passwordOptions
  */
 public function __construct(PasswordOptions $passwordOptions)
 {
     $passwordLengthOptions = $passwordOptions->getLength();
     $this->add(['name' => 'currentPassword', 'required' => true, 'filters' => [['name' => 'StringTrim']], 'validators' => [['name' => 'StringLength', 'options' => ['min' => $passwordLengthOptions['min'], 'max' => $passwordLengthOptions['max']]]]]);
     $this->add(['name' => 'password', 'required' => true, 'filters' => [['name' => 'StringTrim']], 'validators' => [['name' => 'StringLength', 'options' => ['min' => $passwordLengthOptions['min'], 'max' => $passwordLengthOptions['max']]], new PasswordRules($passwordOptions)]]);
     $this->add(['name' => 'passwordVerify', 'required' => true, 'filters' => [['name' => 'StringTrim']], 'validators' => [['name' => 'StringLength', 'options' => ['min' => $passwordLengthOptions['min'], 'max' => $passwordLengthOptions['max']]], ['name' => 'Identical', 'options' => ['token' => 'password']], new PasswordRules($passwordOptions)]]);
 }
Пример #2
0
 /**
  * PasswordFilter constructor.
  * @param PasswordOptions $passwordOptions
  * @param SecretQuestion $secretQuestionService
  */
 public function __construct(PasswordOptions $passwordOptions, SecretQuestion $secretQuestionService)
 {
     $this->passwordOptions = $passwordOptions;
     if ($this->passwordOptions->isSecretQuestion()) {
         $similarText = new SimilarText($secretQuestionService);
         $this->setSimilarText($similarText);
     }
     $passwordLengthOptions = $this->passwordOptions->getLength();
     $this->add(['name' => 'password', 'required' => true, 'filters' => [['name' => 'StringTrim']], 'validators' => [['name' => 'StringLength', 'options' => ['min' => $passwordLengthOptions['min'], 'max' => $passwordLengthOptions['max']]], new PasswordRules($passwordOptions)]]);
     $this->add(['name' => 'passwordVerify', 'required' => true, 'filters' => [['name' => 'StringTrim']], 'validators' => [['name' => 'StringLength', 'options' => ['min' => $passwordLengthOptions['min'], 'max' => $passwordLengthOptions['max']]], ['name' => 'Identical', 'options' => ['token' => 'password']], new PasswordRules($passwordOptions)]]);
 }
Пример #3
0
 /**
  * @param mixed $value
  * @return bool
  */
 public function isValid($value)
 {
     $this->setValue($value);
     $result = true;
     if ($this->passwordOptions->isContainsNumber() && preg_match('/[0-9]/', $value) !== 1) {
         $this->error(self::ERROR_NO_NUMBER);
         $result = false;
     }
     if ($this->passwordOptions->isContainsLowerLetter() && preg_match('/[a-z]/', $value) !== 1) {
         $this->error(self::ERROR_NO_LOWER_CASE_LETTER);
         $result = false;
     }
     if ($this->passwordOptions->isContainsUpperLetter() && preg_match('/[A-Z]/', $value) !== 1) {
         $this->error(self::ERROR_NO_UPPER_CASE_LETTER);
         $result = false;
     }
     if ($this->passwordOptions->isContainsSpecialChar() && preg_match('/[\'\\/~`\\!@#\\$%\\^&\\*\\(\\)_\\-\\+=\\{\\}\\[\\]\\|;:"\\<\\>,\\.\\?\\\\]/', $value) !== 1) {
         $this->error(self::ERROR_NO_SPECIAL_CHAR);
         $result = false;
     }
     return $result;
 }
Пример #4
0
 /**
  * @return bool
  */
 public function isSamePasswordOption()
 {
     return !$this->passwordOption->isDifferentPasswords();
 }