【问题标题】:yii2-adldap does not authenticate AD usersyii2-adldap 不验证 AD 用户
【发布时间】: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。

标签: php yii2 adldap


【解决方案1】:

我应该看到这个。在使用不同的 Active Directory 进行测试后,我发现问题与我的 AD 设置方式有关。将我的代码还原为这个并且它有效(对于某些用户):

   public function validatePassword($attribute, $params)
{


    if (!$this->hasErrors()) {
        $user = $this->getUser();

        if (!$user || !$user->validatePassword($this->password)) {
            $this->addError($attribute, 'Incorrect username or password.');
        }
    }

}

所以我需要与我的系统管理员合作。 谢谢。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-12-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多