我正在尝试使用 yii2-adldap 模块登录,但出现“密码错误”。密码正确。这是我的代码:
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.');
}
}
}
}
我的 getUser 如下:
public function getUser()
{
if ($this->_user === false) {
$this->_user = \Edvlerblog\Adldap2\model\UserDbLdap::findByUsername($this->username);
}
return $this->_user;
}