# Authenticate only with status active (2)

**URL:** <https://discourse.laminas.dev/t/authenticate-only-with-status-active-2/3880>\
**Category:** Components & MVC\
**Tags:** laminas-authentication\
**Created:** [March 26, 2025, 5:32pm UTC](https://discourse.laminas.dev/t/authenticate-only-with-status-active-2/3880 "2025-03-26T17:32:34Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jilco](https://avatars.discourse-cdn.com/v4/letter/j/a88e57/32.png) [@Jilco](https://discourse.laminas.dev/u/Jilco)\
**Post date:** [March 26, 2025, 5:32pm UTC](https://discourse.laminas.dev/t/authenticate-only-with-status-active-2/3880/1 "2025-03-26T17:32:34Z")

</div>

I want to only an active user account with Laminas Authentication, so when status is 2 in the database the login has to proceed. With only email and password everything is working fine, how to add the status in de adapter/authentication?  
I tried this part in the documentation, but did not get it working…

> **[CredentialTreatmentAdapter - laminas-authentication - Laminas Docs](https://docs.laminas.dev/laminas-authentication/adapter/dbtable/credential-treatment/#check-for-active-user)**
>
> laminas-authentication

In my database table “users” there is a column “status”, the script I now use does work, but with a workaround.

```
class AuthenticatieControllerFactory implements FactoryInterface
{
public function __invoke(ContainerInterface $container,
    $requestedName, array $options = null)
{

    $UserTable = $container->get('UserTable');
    //Onderdeel van Authenticatie module om via een database tabel users te verrivieren
    $adapter = new CredentialTreatmentAdapter($container->get('DbAdapter'));
    $adapter->setTableName('users');
    $adapter->setIdentityColumn('email');
    $adapter->setCredentialColumn('password');
    
    // Instantiate the controller and inject dependencies
    return new AuthenticatieController($adapter);
}

```

}  
AuthenticatieController-\>login  
….

```
        $email = $inputFilter->getValue('email');
        $password = $inputFilter->getValue('password');
        $this->adapter->setIdentity($email);
        $this->adapter->setCredential(User::encrypt($password));
         
        $auth->setAdapter($this->adapter);

        $result = $auth->authenticate();
        
        //Checken of account actief is (Status 2)
        $userArray = get_object_vars($this->adapter->getResultRowObject());
        
        if ($userArray['status'] != 2) {
            $message = "Uw account is (nog) niet actief, activeer uw account via de email die u heeft ontvangen na het aanmaken van het account";
            $auth->clearIdentity();
            return ['form' => $form, 'melding' => $message];
        }

        //Checken of email bestaat en Password klopt (via de Laminas adapter)
        if ($result->isValid()) {
            $logged = true;
            return $this->redirect()->toRoute('profiel');
        } else {
            foreach ($result->getMessages() as $message) {
                return ['form' => $form, 'melding' => $message];
            }
        }
    }

```

…..

---

<div class="post-metadata">

**Author:** ![froschdesign](https://yyz2.discourse-cdn.com/flex032/user_avatar/discourse.laminas.dev/froschdesign/32/38_2.png) [@froschdesign](https://discourse.laminas.dev/u/froschdesign)\
**Post date:** [March 26, 2025, 6:41pm UTC](https://discourse.laminas.dev/t/authenticate-only-with-status-active-2/3880/2 "2025-03-26T18:41:32Z")

</div>

You mean something like this:

```php
$authAdapter = new Laminas\Authentication\Adapter\DbTable\CredentialTreatmentAdapter(
    $dbAdapter,
    'user',
    'username',
    'password',
    'SHA1(?) AND deleted = "0"'
);

```

> **[CredentialTreatmentAdapter - laminas-authentication - Laminas Docs](https://docs.laminas.dev/laminas-authentication/adapter/dbtable/credential-treatment/#configuration-options)**
>
> laminas-authentication

---

<div class="post-metadata">

**Author:** ![Jilco](https://avatars.discourse-cdn.com/v4/letter/j/a88e57/32.png) [@Jilco](https://discourse.laminas.dev/u/Jilco)\
**Post date:** [March 26, 2025, 6:47pm UTC](https://discourse.laminas.dev/t/authenticate-only-with-status-active-2/3880/3 "2025-03-26T18:47:56Z")

</div>

Yes! But when i try below it also authenticates with status = 1

```
$adapter = new CredentialTreatmentAdapter($container->get('DbAdapter'),
        'email',
        'password',
        'PASSWORD(?) AND status = "2"'  
        );

```

---

<div class="post-metadata">

**Author:** ![Jilco](https://avatars.discourse-cdn.com/v4/letter/j/a88e57/32.png) [@Jilco](https://discourse.laminas.dev/u/Jilco)\
**Post date:** [March 26, 2025, 8:19pm UTC](https://discourse.laminas.dev/t/authenticate-only-with-status-active-2/3880/4 "2025-03-26T20:19:00Z")

</div>

Solved it with using other adapter (wich is better i think)

```
   $passwordValidation = function ($hash, $password) {
            return password_verify($password, $hash);
        };            
        
        $this->adapter->setCredentialValidationCallback($passwordValidation);
        
        $email = $inputFilter->getValue('email');
        $password = $inputFilter->getValue('password');            
        $this->adapter->setIdentity($email);
        $this->adapter->setCredential($password);
        
        $select = $this->adapter->getDbSelect();
        $select->where('status = 2');
        
        $auth->setAdapter($this->adapter);
        
        $result = $auth->authenticate();

```

---

<div class="post-metadata">

**Author:** ![froschdesign](https://yyz2.discourse-cdn.com/flex032/user_avatar/discourse.laminas.dev/froschdesign/32/38_2.png) [@froschdesign](https://discourse.laminas.dev/u/froschdesign)\
**Post date:** [March 27, 2025, 2:39am UTC](https://discourse.laminas.dev/t/authenticate-only-with-status-active-2/3880/5 "2025-03-27T02:39:47Z")

</div>

The callback and `password_verify` is much better! 👍
