I am trying to login using yii2-adldap module but I am getting "Wrong password error". The password is correct. Here is my code:
public function validatePassword($attribute, $params)
{
if (!$this->hasErrors()) {
$user = $this->getUser();
if (!$user) {
$this->addError('username', 'Incorrect username.');
} else {
$userprincipalname = $this->_user->queryLdapUserObject()->getAttribute('userprincipalname');
if(! Yii::$app->ad->auth()->attempt($userprincipalname[0], $this->password)){
$this->addError('password', 'Incorrect password.');
}
}
}
}
And my getUser is below:
public function getUser()
{
if ($this->_user === false) {
$this->_user = \Edvlerblog\Adldap2\model\UserDbLdap::findByUsername($this->username);
}
return $this->_user;
}
I should have seen this. After testing with a different Active Directory I found out that the problem has to do with how my AD is setup. Reverted my code to this and it worked (for some users):
public function validatePassword($attribute, $params)
{
if (!$this->hasErrors()) {
$user = $this->getUser();
if (!$user || !$user->validatePassword($this->password)) {
$this->addError($attribute, 'Incorrect username or password.');
}
}
}
So I need to work with my System Administrator. Thank you.