Exemplo n.º 1
0
 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;
     }
 }
Exemplo n.º 2
0
 public function __construct($dbAdapter, $config)
 {
     $callback = function ($passwordInDatabase, $passwordProvided) {
         return password_verify($passwordProvided, $passwordInDatabase);
     };
     parent::__construct($dbAdapter, $config['table'], $config['identifier_field'], $config['credential_field'], $callback);
     $this->getDbSelect()->where(array('domain' => 'local'));
 }
Exemplo n.º 3
0
 public function factory_auth_adapter_wordpress(ServiceManager $sm)
 {
     /** @var \Zend\Db\Adapter\Adapter $db */
     $db = $sm->get('Zend\\Db\\Adapter\\Adapter');
     $config = $sm->get('zf2authwordpress\\config');
     $adapter = new CallbackCheckAdapter($db);
     $callable = [$this, 'wp_authenticate'];
     $adapter->setTableName($config['prefix'] . 'users');
     $adapter->setIdentityColumn('user_login');
     $adapter->setCredentialColumn('user_pass');
     $adapter->setCredentialValidationCallback(function ($hash, $password) use($sm, $callable) {
         return call_user_func($callable, $hash, $password, $sm);
     });
     return $adapter;
 }
 /**
  * Prepare Authentication Adapter
  *
  * @return DbTable Provides a fluent interface
  */
 public function prepareAdapter()
 {
     $authenticationAdapter = new AuthenticationAdapterDbTable($this->getZendDb(), $this->getTableName(), $this->getIdentityColumn(), $this->getCredentialColumn(), $this->getCredentialValidationCallback());
     $dbSelect = $authenticationAdapter->getDbSelect();
     if ($this->getCheckStatusColumn() === true) {
         $dbSelect->where([sprintf('%s.status', $this->getTableName()) => 1]);
     }
     $joinTables = $this->getJoinTables();
     if (!empty($joinTables)) {
         foreach ($joinTables as $joinTable) {
             if (!empty($joinTable['name'])) {
                 $dbSelect->join($joinTable['name'], $joinTable['on'], $joinTable['columns'], $joinTable['type']);
                 if ($this->getCheckStatusColumn() === true) {
                     $dbSelect->where([sprintf('%s.status', $joinTable['name']) => 1]);
                 }
             }
         }
     }
     $this->setAdapter($authenticationAdapter);
     return $this;
 }