【发布时间】:2018-09-18 19:00:50
【问题描述】:
我正在尝试使用 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;
}
【问题讨论】:
-
你确认 userprincipalname 返回了什么?
-
我尝试了一个不同的广告,它可以工作。我的公司广告给了我
Adldap\Auth\BindException: Invalid credentials in。我可以查询,但不能验证密码。 -
听起来你需要尝试 samaccountname 而不是 userprincipalname。