当前位置: 首页>>代码示例>>PHP>>正文


PHP DefaultPasswordHasher::check方法代码示例

本文整理汇总了PHP中Cake\Auth\DefaultPasswordHasher::check方法的典型用法代码示例。如果您正苦于以下问题:PHP DefaultPasswordHasher::check方法的具体用法?PHP DefaultPasswordHasher::check怎么用?PHP DefaultPasswordHasher::check使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Cake\Auth\DefaultPasswordHasher的用法示例。


在下文中一共展示了DefaultPasswordHasher::check方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: login

 /**
  * Login action
  *
  * @return void|\Cake\Network\Response
  */
 public function login()
 {
     $failedCount = $this->Cookie->read('fail.auth');
     if ($this->request->is('post')) {
         Event::dispatch('Controller.Users.beforeLogin', $this);
         if ($user = $this->Auth->identify()) {
             $this->Auth->setUser($user);
             Event::dispatch('Controller.Users.successLogin', $this);
             return $this->redirect($this->Auth->redirectUrl());
         }
         if ($this->request->data('username') && $this->request->data('password')) {
             $user = $this->Users->findByUsername($this->request->data('username'))->first();
             $hasher = new DefaultPasswordHasher();
             if (isset($user->id) && $hasher->check($this->request->data('password'), $user->password) && $user->status == UN_PUBLISH_STATUS) {
                 $hasRedirect = true;
                 $this->Flash->warning(__d('community', '«{0}», please activate your account', sprintf('<strong>%s</strong>', $user->name)));
             }
         }
         Event::dispatch('Controller.Users.failLogin', $this);
         if (isset($hasRedirect)) {
             return $this->redirect($this->Auth->config('loginAction'));
         }
         $this->Flash->error(__d('community', 'Username or password is incorrect'));
     }
     $this->set('failedCount', $failedCount);
     $this->set('page_title', __d('community', 'Sign in'));
 }
开发者ID:Cheren,项目名称:union,代码行数:32,代码来源:UsersController.php

示例2: checkPassword

 /**
  * Check if passwords matches
  *
  * @param string $password Password
  * @return boolean
  */
 public function checkPassword($password)
 {
     $hasher = new DefaultPasswordHasher();
     return $hasher->check($password, $this->password);
 }
开发者ID:martinmayer,项目名称:notejam,代码行数:11,代码来源:User.php

示例3: password

 public function password()
 {
     $id = $this->request->session()->read('Auth.User.id');
     if ($this->request->is(['patch', 'post', 'put'])) {
         $user = $this->Users->get($id);
         $hasher = new DefaultPasswordHasher();
         if ($this->request->data['password'] != $this->request->data['repeatPassword']) {
             $this->Flash->error('Senha repetida não confere.');
         } else {
             if (!preg_match('/[A-Za-z0-9]{6,8}/', $this->request->data['password'])) {
                 $this->Flash->error('Nova senha inválida. A senha deve ser composta de números e/ou letras, e ter de 6 a 8 caracteres.');
             } else {
                 if (!$hasher->check($this->request->data['oldPassword'], $user['password'])) {
                     // debug($hasher->check($this->request->data['oldPassword'],$user['password']));
                     $this->Flash->error('Senha antiga não confere.');
                 } else {
                     $user = $this->Users->patchEntity($user, $this->request->data);
                     if ($this->Users->save($user)) {
                         $this->Flash->success(__('Nova senha definida com sucesso.'));
                         return $this->redirect(['action' => 'view']);
                     } else {
                         $this->Flash->error(__('A senha não pôde ser salva. Por favor, tente novamente.'));
                     }
                 }
             }
         }
     }
 }
开发者ID:Allan1,项目名称:Project,代码行数:28,代码来源:UsersController.php

示例4: update_info

 /**
  * Update info method
  *
  * @param string|null $id User id.
  * @return void Redirects on successful edit, renders view otherwise.
  * @throws \Cake\Network\Exception\NotFoundException When record not found.
  */
 public function update_info($id = null)
 {
     if (empty($id)) {
         $id = $this->getUserId();
     }
     $user = $this->Users->get($id, ['contain' => []]);
     if ($this->request->is(['patch', 'post', 'put'])) {
         $update_data = $this->request->data;
         $new_password = $update_data['new_password'];
         $confirm_password = $update_data['confirm_password'];
         $dph = new DefaultPasswordHasher();
         if (!$dph->check($update_data['current_password'], $user['password'])) {
             $this->Flash->error('Mật khẩu của bạn không chính xác. <br> Vui lòng thực hiện lại!');
         } else {
             //Kiểm tra password mới
             if (empty($new_password)) {
                 if (!empty($confirm_password)) {
                     $this->Flash->error('Bạn chưa nhập password mới.');
                 }
             } else {
                 if (empty($confirm_password)) {
                     $this->Flash->error('Bạn chưa xác nhận password mới.');
                 } else {
                     if (strcmp($new_password, $confirm_password) !== 0) {
                         $this->Flash->error('Chuỗi xác nhận không trùng với password mới. <br> Vui lòng kiểm tra lại.');
                     } else {
                         $update_data['password'] = $dph->hash($update_data['new_password']);
                         $update_data['updated_at'] = Time::now();
                         $user = $this->Users->patchEntity($user, $update_data);
                         if ($this->Users->save($user)) {
                             $this->Flash->success('Thông tin của bạn đã được cập nhật!');
                             return $this->redirect(['action' => 'index']);
                         } else {
                             $this->Flash->error('Cập nhật thông tin không thành công. Bạn vui lòng thử lại sau!');
                         }
                     }
                 }
             }
         }
     }
     $roles = $this->Users->Roles->find('list', ['limit' => 200]);
     $this->set(compact('user', 'roles'));
     $this->set('_serialize', ['user']);
 }
开发者ID:ansidev,项目名称:cakephp_blog,代码行数:51,代码来源:UsersController.php

示例5: testChangementMotPasse

 /**
  * Test changementMotPasse method
  *
  * @return void
  */
 public function testChangementMotPasse()
 {
     // case call from the link from the email
     if ($this->debug) {
         debug('USERS CONTROLLER - testChangementMotPasse: case call from the link from the email');
     }
     $this->get('/users/changementMotPasse/2400fd3226c673532e8e68d35c8c31115a83f6c3');
     $this->assertResponseOk();
     $this->assertNoRedirect();
     // case authenticated user
     if ($this->debug) {
         debug('USERS CONTROLLER - testChangementMotPasse: case authenticated user');
     }
     $this->session(['Auth.User.id' => 2, 'Auth.User.email' => 'seconduser@somemail.com']);
     $data = ['new_pass' => 'juVni4tr3', 'new_pass_confirm' => 'juVni4tr3', 'password' => 'HuaB78lo'];
     $this->post('/users/changementMotPasse', $data);
     $query = $this->Users->find()->where(['email' => 'seconduser@somemail.com'])->select('password')->first();
     $hasher = new DefaultPasswordHasher();
     $this->assertResponseCode(302);
     $this->assertEquals(true, $hasher->check($data['new_pass'], $query['password']));
     $this->assertRedirect();
     // case non authenticated user
     if ($this->debug) {
         debug('USERS CONTROLLER - testChangementMotPasse: case non authenticated user');
     }
     $this->session(['Auth.User.id' => 2, 'Auth.User.email' => 'seconduser@somemail.com']);
     $data = ['password' => '2400fd3226c673532e8e68d35c8c31115a83f6c3', 'new_pass' => 'juVni4tr3', 'new_pass_confirm' => 'juVni4tr3', 'password' => 'HuaB78lo'];
     $this->post('/users/changementMotPasse', $data);
     $query = $this->Users->find()->where(['email' => 'seconduser@somemail.com'])->select('password')->first();
     $hasher = new DefaultPasswordHasher();
     $this->assertResponseCode(302);
     $this->assertEquals(true, $hasher->check($data['new_pass'], $query['password']));
     $this->assertRedirect();
 }
开发者ID:beyondkeysystem,项目名称:CakePhp3-AppStarter,代码行数:39,代码来源:UsersControllerTest.php

示例6: forgotUsername

 /**
  * Emails a user their username.
  * If they provide a valid password and email address
  *
  */
 public function forgotUsername()
 {
     if ($this->request->is('post')) {
         $data = $this->request->data;
         $userEmail = $this->Users->UserEmails->findByEmail($data['email'])->first();
         $user = $this->Users->get($userEmail['user_id']);
         $ok = DefaultPasswordHasher::check($data['password'], $user['password']);
         if ($ok) {
             // Email the user thier username
             $to = $data['email'];
             $message = 'Here is your username, as requested:' . PHP_EOL . PHP_EOL . 'Username: ' . $user['username'] . PHP_EOL . PHP_EOL . ' -Vooderbot';
             $email = new Email('default');
             $email->transport('mailjet')->from(['vooderbot@vooders.com' => 'Vooders.com'])->to($to)->subject('Heres your username')->send($message);
             $this->redirect(['action' => 'login']);
         } else {
             $this->Flash->error(__('The details you have entered are incorrect'));
             $this->redirect(['action' => 'login']);
         }
     }
 }
开发者ID:Vooders,项目名称:vooders.com,代码行数:25,代码来源:UsersController.php

示例7: validateNewPass

 /**
  * Given the $data operates validations for new password, redirects if it doesn't pass the validation
  * 
  * @param array $data
  * @return bool
  */
 private function validateNewPass($data)
 {
     // Check that pass and confirm pass are equals
     if ($data['new_pass'] !== $data['new_pass_confirm']) {
         $this->Flash->error("Les deux nouveaux mots de passe ne correspondent pas.");
         return false;
     }
     // Check la complexité du nouveau pass
     if (!$this->Users->passwordComplexe($data['new_pass'])) {
         $this->Flash->error("Le nouveau mot de passe ne respecte pas les règles de complexité. (une majuscule minimum, un chiffre minimum, 8 caractères minimum)");
         return false;
     }
     // If it doesn't come from a forget pass, check that old pass is correct
     if ($data['old_pass']) {
         $userEntity = $this->Users->find('all')->where(['id' => $this->Auth->user('id')])->select(['password'])->first();
         $hasher = new DefaultPasswordHasher();
         $bcrypt_pass_check = $hasher->check($data['old_pass'], $userEntity["password"]);
         if (empty($userEntity) || !$bcrypt_pass_check) {
             $this->Flash->error("Le mot de passe actuel n'est pas le bon.");
             return false;
         }
     }
     return true;
 }
开发者ID:beyondkeysystem,项目名称:CakePhp3-AppStarter,代码行数:30,代码来源:UsersController.php

示例8: testEditPOST

 public function testEditPOST()
 {
     // 1. Login, POST a suitable record to the url, redirect, and return the record just
     // posted, as read from the db.
     $fixtureRecord = $this->usersFixture->newUserRecord;
     $fromDbRecord = $this->genericEditPutProlog(FixtureConstants::userAndyAdminId, '/users/edit', $fixtureRecord, '/users', $this->users);
     // 2. Now validate that record.
     $this->assertEquals($fromDbRecord['username'], $fixtureRecord['username']);
     // 3. The password is hashed and needs to be checked using the hashed-password checking mechanism.
     $dph = new DefaultPasswordHasher();
     $this->assertTrue($dph->check($fixtureRecord['password'], $fromDbRecord['password']));
 }
开发者ID:bostontrader,项目名称:duncemaster,代码行数:12,代码来源:UsersControllerTest.php

示例9: checkPassword

 public function checkPassword($password, $currentPass)
 {
     $hasher = new DefaultPasswordHasher();
     return $hasher->check($password, $currentPass);
 }
开发者ID:oxenti,项目名称:user,代码行数:5,代码来源:UsersTable.php

示例10: passwordMatch

 public static function passwordMatch($pw, $hashedPw)
 {
     $hasher = new DefaultPasswordHasher();
     return $hasher->check($pw, $hashedPw);
 }
开发者ID:gpsoft,项目名称:lanmap,代码行数:5,代码来源:User.php


注:本文中的Cake\Auth\DefaultPasswordHasher::check方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。