Gc\User\Model::authenticate PHP Method

authenticate() public method

Authenticate user
public authenticate ( string $login, string $password ) : boolean
$login string Login
$password string Password
return boolean
    public function authenticate($login, $password)
    {
        $authAdapter = new Adapter\DbTable\CredentialTreatmentAdapter($this->getAdapter());
        $authAdapter->setTableName($this->name);
        $authAdapter->setIdentityColumn('login');
        $authAdapter->setCredentialColumn('password');
        $authAdapter->setCredentialTreatment('? AND active = TRUE');
        $authAdapter->setIdentity($login);
        $authAdapter->setCredential(sha1($password));
        $auth = new AuthenticationService(new Storage\Session(self::BACKEND_AUTH_NAMESPACE));
        $result = $auth->authenticate($authAdapter);
        $this->events()->trigger(__CLASS__, 'before.auth', $this);
        if ($result->isValid()) {
            $data = $authAdapter->getResultRowObject(null, 'password');
            $this->setData((array) $data);
            $this->setOrigData();
            $auth->getStorage()->write($this);
            $this->events()->trigger(__CLASS__, 'after.auth', $this);
            return true;
        }
        $this->events()->trigger(__CLASS__, 'after.auth.failed', $this, array('login' => $login));
        return false;
    }

Usage Example

 /**
  * Initialize test
  *
  * @return void
  */
 public function init()
 {
     parent::setUp();
     $this->user = UserModel::fromArray(array('lastname' => 'Test', 'firstname' => 'Test', 'email' => '*****@*****.**', 'login' => 'test-user-model', 'user_acl_role_id' => 1, 'active' => true));
     $this->user->setPassword('test-user-model-password');
     $this->user->save();
     $this->user->authenticate('test-user-model', 'test-user-model-password');
     $configuration = (include GC_APPLICATION_PATH . '/config/application.config.php');
     $configuration['module_listener_options']['config_glob_paths'] = array('tests/config/local.php');
     $this->setApplicationConfig($configuration);
 }
All Usage Examples Of Gc\User\Model::authenticate