Authenticate only with status active (2)

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…

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];
            }
        }
    }

…..

You mean something like this:

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

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

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

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();

The callback and password_verify is much better! :+1: