Пример #1
0
 /**
  * Trims and validates password against regex
  * 
  * @param string $password
  * @return string
  * @throws Exception
  */
 public static function validatePassword($password)
 {
     $validator = new Regex(['pattern' => '/((?=.*\\d)(?=.*[a-zA-Z]).{8,20})/U']);
     if (!$validator->isValid((new StringTrim())->filter($password))) {
         throw new Exception(Json::encode($validator->getMessages()));
     }
     return $password;
 }
Пример #2
0
 /**
  * Ensures that getMessages() returns expected default value
  *
  * @return void
  */
 public function testGetMessages()
 {
     $validator = new Validator\Regex('/./');
     $this->assertEquals(array(), $validator->getMessages());
 }
Пример #3
0
 /**
  * change password processing
  * @return ViewModel
  */
 public function updatePwAction()
 {
     $id = $this->params()->fromPost('login_id');
     $pw = $this->params()->fromPost('login_pw');
     $key = $this->params()->fromPost('key_id');
     $new_pw = $this->params()->fromPost('new_pw');
     $token_id = $this->params()->fromPost('token_id');
     $sess_token_id = $this->container()->get('token_id');
     $this->container()->clear('token_id');
     // when can't get require item
     if (!$id || !$pw || !$key || !$new_pw || !$token_id || !$sess_token_id || $token_id != $sess_token_id) {
         return $this->redirect()->toRoute('app', array('controller' => 'index'));
     }
     $this->container()->set('login_id', $id);
     $user = new UserEntity();
     $row = $user->db()->getLoginInfo($id, $key);
     $success = false;
     $ngCount = false;
     $message = null;
     if (!$row->user_no) {
         $message = "Unknown account";
         //            $message = "アカウントは不明です。";
     } else {
         if (LOGIN_FAILED_COUNT && LOGIN_FAILED_COUNT <= $row->ng_count) {
             $message = "Account is locked";
             //            $message = "アカウントはロックされています。";
         } else {
             if (!$row->login_pw || md5($row->login_pw . $token_id) != $pw) {
                 $message = "Failed";
                 //            $message = "認証に失敗しました。";
                 $ngCount = true;
             } else {
                 if ($id == $new_pw) {
                     $message = "Don't use same password as ID";
                     //            $message = "ログインIDと同じパスワードは使用できません。";
                 } else {
                     $success = true;
                 }
             }
         }
     }
     // save login error number
     if (!$success && $ngCount) {
         $user->db()->insertLoginFailed($row->user_no);
     }
     if ($success) {
         $ret = $user->db()->checkLoginPw($row->user_no, $new_pw);
         if ($ret) {
             $message = "Don't use same password as past one.";
             //                $message = "過去利用したパスワードは設定出来ません。";
             $success = false;
         }
     }
     $tmp_message = "Confirm password policy\n";
     //        $tmp_message = "パスワードポリシーに違反しています。\n";
     if ($success) {
         $validate = new StringLength();
         $validate->setOptions(array('min' => (int) PW_MIN_LENGTH, 'max' => (int) PW_MAX_LENGTH, 'encoding' => 'UTF-8'));
         $ret = $validate->isValid($new_pw);
         if (!$ret) {
             $message = $tmp_message . current($validate->getMessages());
             $success = false;
         }
     }
     if ($success && strlen(PW_REGEX_PATTERN)) {
         unset($validate);
         $validate = new Regex(array('pattern' => PW_REGEX_PATTERN));
         $ret = $validate->isValid($new_pw);
         if (!$ret) {
             $message = $tmp_message . current($validate->getMessages());
             $success = false;
         }
     }
     // save error message & redirect to input form
     if ($message || !$success) {
         $this->flashMessenger()->addMessage($message);
         return $this->redirect()->toRoute('app', array('controller' => 'index', 'action' => 'change-pw'));
     }
     $ret = $user->changePw($row->user_no, $new_pw, 0);
     $message .= 'Change password ' . ($ret ? 'success' : 'failed');
     //                . ($ret ?  '成功しました。' : '失敗しました。');
     $this->flashMessenger()->addMessage($message);
     if ($ret) {
         return $this->redirect()->toRoute('app', array('controller' => 'index'));
     } else {
         return $this->redirect()->toRoute('app', array('controller' => 'index', 'action' => 'change-pw'));
     }
     $view = new ViewModel();
     $view->setTerminal(true);
     return $view;
 }
Пример #4
0
 /**
  * @ZF-11863
  * @dataProvider specialCharValidationProvider
  */
 public function testSpecialCharValidation($expected, $input)
 {
     $validator = new Regex('/^[[:alpha:]\']+$/iu');
     $this->assertEquals($expected, $validator->isValid($input), 'Reason: ' . implode('', $validator->getMessages()));
 }
Пример #5
0
 /**
  * @ZF-11863
  * @dataProvider specialCharValidationProvider
  */
 public function testSpecialCharValidation($expected, $input)
 {
     // Locale changed due a bug with PHP versions lower than 5.3.4 (https://bugs.php.net/bug.php?id=52971)
     //setlocale(LC_ALL, 'Spanish_Spain', 'es_ES', 'es_ES.utf-8');
     if (version_compare(PHP_VERSION, '5.3.4', '<')) {
         $this->markTestIncomplete("Test skipped because the PHP version is lower than 5.3.4 or the environment don't support quoted characters");
     }
     $validator = new Regex('/^[[:alpha:]\']+$/iu');
     $this->assertEquals($expected, $validator->isValid($input), 'Reason: ' . implode('', $validator->getMessages()));
 }