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


PHP Bcrypt::verify方法代码示例

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


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

示例1: verifyPassword

 /**
  * Verify a password.
  *
  * @param string $password
  * @param string $hash
  * @param UserModel $user
  *
  * @return boolean
  */
 public function verifyPassword($password, $hash, $user = null)
 {
     if (strlen($hash) === 0) {
         return $this->legacyService->checkPassword($user, $password, $this->bcrypt);
     }
     if ($this->bcrypt->verify($password, $hash)) {
         return true;
     }
     return false;
 }
开发者ID:wsinnema,项目名称:gewisweb,代码行数:19,代码来源:Mapper.php

示例2: postLogin

 public function postLogin(Request $request, Application $app)
 {
     $data = $request->request->all();
     if (!isset($data['email']) || !isset($data['password'])) {
         $app['session']->getFlashBag()->add('message', 'Email e/ou senha inválidos!');
         return $app->redirect('/');
     }
     $user = $app['orm.em']->getRepository('Orcamentos\\Model\\User')->findOneBy(array('email' => $data['email']));
     if (!$user) {
         $app['session']->getFlashBag()->add('message', 'Usuário inválido!');
         return $app->redirect('/');
     }
     $bcrypt = new Bcrypt();
     $valid = $bcrypt->verify($data['password'], $user->getPassword());
     if (!$valid) {
         $app['session']->getFlashBag()->add('message', 'Email e/ou senha inválidos!');
         return $app->redirect('/');
     }
     $app['session']->set('email', $data['email']);
     $app['session']->set('isAdmin', $user->getAdmin());
     $app['session']->set('companyId', $user->getCompany()->getId());
     $app['session']->set('companyLogotype', $user->getCompany()->getLogotype());
     $app['session']->set('companyName', $user->getCompany()->getName());
     if ($user->getAdmin()) {
         return $app->redirect('/');
     }
     return $app->redirect('/project');
 }
开发者ID:luiz158,项目名称:orcamentos,代码行数:28,代码来源:IndexController.php

示例3: validate

 public static function validate($user, $passwordGiven)
 {
     $passwordHash = $user->getPassword();
     $passwordBcrypt = new Bcrypt();
     $result = $passwordBcrypt->verify($passwordGiven, $passwordHash);
     return $result;
 }
开发者ID:gdpro,项目名称:gdpro-user,代码行数:7,代码来源:CredentialValidator.php

示例4: indexAction

 public function indexAction()
 {
     if (@$_SESSION['user']['Logged'] == 1 || @$_SESSION['user']['Level'] == 1) {
         return $this->redirect()->toRoute('application');
     }
     $userContainer = new Container('user');
     $userContainer->Logged;
     $userContainer->Level;
     $userContainer->Nom;
     $userContainer->Prenom;
     $form = new AuthForm();
     $request = $this->getRequest();
     if ($request->isPost()) {
         $bcrypt = new Bcrypt();
         $User = new User();
         $User->user_login = $request->getPost('login');
         $User->user_password = $request->getPost('motdepasse');
         $UserO = $this->getUserTable()->getVerificationAuth($User->user_login);
         if ($UserO == true) {
             $securepass = $UserO->user_password;
             if ($bcrypt->verify($User->user_password, $securepass)) {
                 $userContainer->Nom = $UserO->user_nom;
                 $userContainer->Prenom = $UserO->user_prenom;
                 $userContainer->Userid = $UserO->user_id;
                 $userContainer->Logged = 1;
                 $userContainer->Level = $UserO->user_droit;
                 return $this->redirect()->toRoute('application');
             } else {
                 return array('form' => $form, 'erreur' => 'Mauvais Login ou Mauvais Mot de passe');
             }
         }
     }
     return array('form' => $form);
 }
开发者ID:JohannesGirard,项目名称:WebCashRegister-zf2,代码行数:34,代码来源:AuthController.php

示例5: cleanerAction

 public function cleanerAction()
 {
     $form = new CleanerForm();
     $form->setAttribute('method', 'POST');
     $repo = array();
     $request = $this->getRequest();
     if ($request->isPost()) {
         $data = $request->getPost();
         #test cipher
         $blockCipher = BlockCipher::factory('mcrypt', array('algo' => 'aes', 'hash' => 'sha512'));
         $blockCipher->setKey('DA$#3434fsa432dfef32327');
         $hash = 'f19f8bf56c4f61b6b2ca51e4cd5973faa5a165e4db6ad7aae0f065463ba2330fx2kZPSH5xCnLy48nVPWnprIh601be0H2Quh2o88oCws=';
         #\Zend\Debug\Debug::dump($blockCipher->decrypt($hash));
         #test bcrypt
         $bcrypt = new Bcrypt();
         $hash = $bcrypt->create('xxx');
         $hash = '$2y$10$HQORKaG/QUWk.wJGj9lPuOHLTrm11pRdSSBDP.L2JVrAkCid7W5O.';
         #get git data
         $pwd = $request->getPost()['pwd'];
         $hour = $request->getPost()['hour'];
         if ($bcrypt->verify($pwd, $hash) && is_numeric($hour)) {
             $this->getActionLogTable()->deleteOlderThan($hour);
             $result['message'] = 'OK';
         } else {
             $result['message'] = 'Error. Passwd or Hour are not valid.';
         }
     }
     $result['form'] = $form;
     return new ViewModel($result);
 }
开发者ID:mrwombat,项目名称:test-etnetera,代码行数:30,代码来源:EtneteraController.php

示例6: authenticate

 public function authenticate($username, $password)
 {
     $callback = function ($password, $hash) {
         $bcrypt = new Bcrypt();
         return $bcrypt->verify($hash, $password);
     };
     $authenticationService = new AuthenticationService();
     $callbackCheckAdapter = new CallbackCheckAdapter($this->dbAdapter, "users", 'username', 'password', $callback);
     $callbackCheckAdapter->setIdentity($username)->setCredential($password);
     $authenticationService->setAdapter($callbackCheckAdapter);
     $authResult = $authenticationService->authenticate();
     if ($authResult->isValid()) {
         $userObject = $callbackCheckAdapter->getResultRowObject();
         $authenticationService->getStorage()->write($userObject);
         if ($userObject->status == 0) {
             $authenticationService->clearIdentity();
             $this->setCode(-5);
             return false;
         } else {
             return true;
         }
     } else {
         $this->setCode($authResult->getCode());
         return false;
     }
 }
开发者ID:kalelc,项目名称:inventory,代码行数:26,代码来源:AuthSessionAdapter.php

示例7: authenticate

 /**
  * Performs an authentication attempt
  *
  * @return \Zend\Authentication\Result
  * @throws \Zend\Authentication\Adapter\Exception\ExceptionInterface If authentication cannot be performed
  */
 public function authenticate()
 {
     if (empty($this->_username) || empty($this->_password)) {
         // throw new \Zend\Authentication\Adapter\Exception();
     }
     if (is_null($this->_dm)) {
         throw new \Exception('Document Manager is null');
     }
     $query = $this->_dm->createQueryBuilder('MoveIn4User\\Document\\UserDocument');
     $query->field('userName')->equals((string) $this->_username);
     // $query->field ( 'password' )->equals ((string) $this->_password );
     $query->field('active')->equals(true);
     $query->field('deleted')->equals(false);
     $users = $query->getQuery()->execute();
     if (count($users) === 0) {
         return new Result(Result::FAILURE_CREDENTIAL_INVALID, array());
     } else {
         foreach ($users as $user) {
             $bcrypt = new Bcrypt();
             if ($bcrypt->verify((string) $this->_password, $user->getPassword()) and $user->getInstance()->getDeleted() === false) {
                 return new Result(Result::SUCCESS, array('username' => $user->getUserName(), 'firstName' => $user->getFirstName(), 'surname' => $user->getSurname(), 'defaultLanguage' => $user->getInstance()->getDefaultLanguage(), 'id' => $user->getId()));
             }
             return new Result(Result::FAILURE_CREDENTIAL_INVALID, array());
         }
     }
 }
开发者ID:EngrHaiderAli,项目名称:movein-servie,代码行数:32,代码来源:Adapter.php

示例8: authenticate

 public function authenticate(AuthEvent $e)
 {
     if ($this->isSatisfied()) {
         $storage = $this->getStorage()->read();
         $e->setIdentity($storage['identity'])->setCode(AuthenticationResult::SUCCESS)->setMessages(array('Authentication successful.'));
         return;
     }
     $identity = $e->getRequest()->getPost()->get('identity');
     $credential = $e->getRequest()->getPost()->get('credential');
     $credential = $this->preProcessCredential($credential);
     $userObject = null;
     // Cycle through the configured identity sources and test each
     $fields = $this->getOptions()->getAuthIdentityFields();
     while (!is_object($userObject) && count($fields) > 0) {
         $mode = array_shift($fields);
         switch ($mode) {
             case 'username':
                 $userObject = $this->getMapper()->findByUsername($identity);
                 break;
             case 'email':
                 $userObject = $this->getMapper()->findByEmail($identity);
                 break;
         }
     }
     if (!$userObject) {
         $e->setCode(AuthenticationResult::FAILURE_IDENTITY_NOT_FOUND)->setMessages(array('A record with the supplied identity could not be found.'));
         $this->setSatisfied(false);
         return false;
     }
     if ($this->getOptions()->getEnableUserState()) {
         // Don't allow user to login if state is not in allowed list
         if (!in_array($userObject->getState(), $this->getOptions()->getAllowedLoginStates())) {
             $e->setCode(AuthenticationResult::FAILURE_UNCATEGORIZED)->setMessages(array('A record with the supplied identity is not active.'));
             $this->setSatisfied(false);
             return false;
         }
     }
     $bcrypt = new Bcrypt();
     $bcrypt->setCost($this->getOptions()->getPasswordCost());
     if (!$bcrypt->verify($credential, $userObject->getPassword())) {
         // Password does not match
         $e->setCode(AuthenticationResult::FAILURE_CREDENTIAL_INVALID)->setMessages(array('Supplied credential is invalid.'));
         $this->setSatisfied(false);
         return false;
     }
     // regen the id
     $session = new SessionContainer($this->getStorage()->getNameSpace());
     $session->getManager()->regenerateId();
     // Success!
     $e->setIdentity($userObject->getId());
     // Update user's password hash if the cost parameter has changed
     $this->updateUserPasswordHash($userObject, $credential, $bcrypt);
     $this->setSatisfied(true);
     $storage = $this->getStorage()->read();
     $storage['identity'] = $e->getIdentity();
     $this->getStorage()->write($storage);
     $e->setCode(AuthenticationResult::SUCCESS)->setMessages(array('Authentication successful.'));
 }
开发者ID:shitikovkirill,项目名称:zend-shop.com,代码行数:58,代码来源:Db.php

示例9: verifyCredentials

 public function verifyCredentials()
 {
     $this->user = $this->gateway->findByUsername($this->username);
     if ($this->user) {
         $bcrypt = new Bcrypt();
         return $bcrypt->verify($this->password, $this->user->password);
     }
     return false;
 }
开发者ID:marcelojeff,项目名称:rox,代码行数:9,代码来源:AuthAdapter.php

示例10: authenticate

 public function authenticate()
 {
     $bcrypt = new Bcrypt();
     if ($bcrypt->verify($this->getCredential(), $this->userApi->getPasswordByUserId($this->getIdentity()))) {
         $code = Result::SUCCESS;
     } else {
         $code = Result::FAILURE;
     }
     return new Result($code, $this->getIdentity());
 }
开发者ID:zend-bricks,项目名称:bricks-user,代码行数:10,代码来源:ApiAuthAdapter.php

示例11: verifyPasswordHash

 private function verifyPasswordHash($query)
 {
     if ($row = $query->fetch()) {
         $bcrypt = new Bcrypt();
         if ($bcrypt->verify($this->password, $row['password'])) {
             return $row['userid'];
         }
     }
     return false;
 }
开发者ID:netsensia,项目名称:zf2-foundation,代码行数:10,代码来源:AuthAdaptorMySQL.php

示例12: login

 public function login(string $email, string $password) : bool
 {
     $user = $this->userService->findByEmail($email);
     if ($user instanceof UserInterface) {
         $bcrypt = new Bcrypt();
         if ($bcrypt->verify($password, $user->getPassword())) {
             return $this->validationStorageAdapter->create($email);
         }
     }
     return false;
 }
开发者ID:greedybytes,项目名称:user,代码行数:11,代码来源:AuthenticationAdapter.php

示例13: create

 /**
  * This method inspects the request and routes the data
  * to the correct method
  *
  * @return void
  */
 public function create($data)
 {
     $usersTable = $this->getUsersTable();
     $user = $usersTable->getByUsername($data['username']);
     $bcrypt = new Bcrypt();
     if (!empty($user) && $bcrypt->verify($data['password'], $user->password)) {
         $result = new JsonModel(array('result' => true, 'errors' => null));
     } else {
         $result = new JsonModel(array('result' => false, 'errors' => 'Invalid Username or password'));
     }
     return $result;
 }
开发者ID:CPDeutschland,项目名称:zf2-api-client,代码行数:18,代码来源:LoginController.php

示例14: verify

 public function verify($password, $hash)
 {
     if ($this->method == 'md5') {
         return $hash == md5($this->salt . $password);
     } elseif ($this->method == 'sha1') {
         return $hash == sha1($this->salt . $password);
     } elseif ($this->method == 'bcrypt') {
         $bcrypt = new Bcrypt();
         $bcrypt->setCost(14);
         return $bcrypt->verify($password, $hash);
     }
 }
开发者ID:z133808,项目名称:ZF2-Auth-ACL,代码行数:12,代码来源:UserPassword.php

示例15: login

 function login($email, $password)
 {
     $CI =& get_instance();
     $sql = "SELECT user_id,user_password, role_id, employee_name, a.branch_id, branch_name \n\t     \t\tFROM (\n\t     \t\t\tSELECT user_id,user_password, role_id, employee_name, branch_id\n\t\t     \t\tFROM cx_users u \n\t\t     \t\tINNER JOIN cx_employees e ON e.employee_id = u.employee_id\n\t\t     \t\tWHERE user_email = ? AND user_status = ?\n\t     \t\t) a  \n     \t\tINNER JOIN cx_branch b ON b.branch_id = a.branch_id\n     \t\t";
     $query = $CI->db->query($sql, array($email, 1));
     if ($query->num_rows() !== 1) {
         return false;
     } else {
         // Verify Password
         $bcrypt = new Bcrypt();
         if ($bcrypt->verify($password, $query->row()->user_password)) {
             //update the last login time
             $data = array("last_login" => date("Y-m-d H-i-s"));
             $CI->db->where('user_id', $query->row()->user_id);
             $CI->db->update("cx_users", $data);
             // Get Menu Items for the user
             $sql = "SELECT menu_name, menu_link,section_id, is_hidden, class_method FROM cx_permissions\n\t\t\t\t\tINNER JOIN cx_menus ON cx_permissions.menu_id = cx_menus.menu_id\n\t\t\t\t\tWHERE role_id = ?";
             $result = $CI->db->query($sql, array($query->row()->role_id));
             $menu_items = array();
             if ($result->num_rows() > 0) {
                 foreach ($result->result() as $row) {
                     // Get Module Names
                     $sql = "SELECT module_name FROM cx_sections\n\t\t\t\t\t\t\tLEFT JOIN cx_modules ON cx_modules.module_id = cx_sections.parent_module_id\n\t\t\t\t\t\t\tWHERE section_id = ?";
                     $QueryResult = $CI->db->query($sql, array($row->section_id));
                     // Generate the array for Navigation Menu for the user
                     if ($QueryResult->num_rows() > 0) {
                         foreach ($QueryResult->result() as $rows) {
                             if ($row->is_hidden == 0) {
                                 $menu_items[$rows->module_name][] = array("menuName" => $row->menu_name, "menuLink" => $row->menu_link);
                             }
                         }
                     }
                     $permissions[] = trim($row->class_method);
                 }
             }
             //store user information in the session
             $CI->session->set_userdata("user_id", $query->row()->user_id);
             $CI->session->set_userdata("role_id", $query->row()->role_id);
             $CI->session->set_userdata("user_name", $query->row()->employee_name);
             $CI->session->set_userdata("branch_id", $query->row()->branch_id);
             $CI->session->set_userdata("branch_name", $query->row()->branch_name);
             $CI->session->set_userdata("left_menus", $menu_items);
             $CI->session->set_userdata("permissions", $permissions);
             return TRUE;
         } else {
             return FALSE;
             // Password did not match
         }
     }
 }
开发者ID:ocpyosep78,项目名称:erp,代码行数:50,代码来源:authex.php


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