[英]Which Active Directory's attribute corresponds to the “bind_password” parameter of the ldap_bind function in PHP
我正在創建一個 API 用於 Active Directory 的注冊和身份驗證。
注冊時,我使用“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
);
}
有人能幫我嗎。
使用普通存儲的密碼是行不通的,需要進行一些編碼,但是有一個 mutator unicodePwd
會為你處理它。 嘗試
$user = new User([
'cn' => $full_name,
'unicodePwd ' => $password,
'samaccountname' => $username,
'mail' => $email
]);
用於設置帳戶密碼的屬性是unicodePwd
。 該屬性只能設置,不能讀取。
Microsoft 文檔中描述了有關您放在那里的內容的格式有一些嚴格的要求。 但是,根據他們的文檔,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.
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.