【问题标题】:Which Active Directory's attribute corresponds to the "bind_password" parameter of the ldap_bind function in PHP哪个Active Directory的属性对应PHP中ldap_bind函数的“bind_password”参数
【发布时间】:2020-04-27 15:24:26
【问题描述】:

我正在为 Active Directory 的注册和身份验证创建 API。

注册时,我使用“userPassword”字段存储密码。

$user = new User([
    'cn' => $full_name,
    'userPassword' => $password,
    'samaccountname' => $username,
    'mail' => $email
]);

$user->inside(config('ldap.connections.default.base_dn'));

$user->save();

注册工作正常。 但在身份验证时,Active Directory 无法识别提供的密码:

$user = User::where('samaccountname', '=', $username)->firstOrFail(); // all is good here. print_r($user) shows user details

if (Container::getDefaultConnection()->auth()->attempt($user['distinguishedname'], $password)) {

    // returns a response to the user
    return \response()->json(
        new UserResource($user), 200
    );

} else {

    return \response()->json(
        [
            'message' => 'invalid credentials or user not exists.'
        ], 403
    );
}

谁能帮帮我。

【问题讨论】:

  • 您为这个 LDAP 使用了哪个包?你能试试吗:if (Container::getDefaultConnection()->auth()->attempt($user->distinguishedname, $user->userPassword))
  • 我正在使用 LdapRecord。从这里https://ldaprecord.com/

标签: php laravel active-directory ldap


【解决方案1】:

使用普通存储密码是行不通的,需要进行一些编码,但有一个突变器unicodePwd 可以为您处理。试试

$user = new User([
    'cn' => $full_name,
    'unicodePwd ' => $password,
    'samaccountname' => $username,
    'mail' => $email
]);

【讨论】:

  • 感谢您的回复。现在我收到以下错误消息:ldap_add(): Add: Server is unwilling to perform
  • 你设置启用标志了吗? (512)
  • 是,但没有变化。也许我必须和我的系统管理员见面。
  • 我也有同样的问题
【解决方案2】:

用于设置帐户密码的属性是unicodePwd。该属性只能设置,不能读取。

对于您所放内容的格式有一些严格的要求,这些要求在 Microsoft 文档中进行了描述。但是,根据their documentation,LdapRecord 库会为您处理:

你在用户unicodePwd属性上设置的密码字符串是自动编码的,你不需要自己编码。

他们关于如何创建 AD 用户的示例如下所示:

$user = (new User)->inside('ou=Users,dc=local,dc=com');

$user->cn = 'John Doe';
$user->samaccountname = 'jdoe';
$user->unicodePwd = 'SecretPassword';
$user->userPrincipalName = 'jdoe@acme.org';

$user->save();

// Enable the user.
$user->userAccountControl = 512;

try {
    $user->save();
} catch (\LdapRecord\LdapRecordException $e) {
    // Failed saving user.
}

【讨论】:

  • 同样的结果。我联系了我的系统管理员以查看活动目录中是否存在限制。我会回来的。
  • 如果您使用 userPassword 的旧方式有效,请使用它。但是您必须将userAccountControl 设置为512 (NORMAL_ACCOUNT),否则该帐户将被禁用。除非您另行指定,否则所有帐户均已禁用。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2023-04-04
  • 1970-01-01
  • 1970-01-01
  • 2023-03-26
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多