[英]LDAP Authenticating user in PHP
我正在构建从PHP到LDAP的身份验证脚本。 我的问题是,如果该用户不是我的管理员,我真的不知道如何检查该用户。
我不太了解ldap_bind
在这里我只能以管理员用户身份登录,但是随后我可以在自己的ou中搜索其他用户,但是我不知道如何检查他们的密码。
到目前为止,我有:
function login($up, $pw){
$ldap = ldap_connect("dejan.local") or die("Could not connect to LDAP server.");
if ($ldap){
ldap_set_option($ldap, LDAP_OPT_REFERRALS, 0);
ldap_set_option($ldap, LDAP_OPT_PROTOCOL_VERSION, 3);
//if I try $up and $pw here, I get an error
if ($bind = ldap_bind($ldap, "Admin", "Somepassword")){
$sr = ldap_search($ldap, "ou=testunit,DC=dejan,DC=local", "samaccountname=$up");
$info = ldap_get_entries($ldap, $sr);
//so here I've gotten information from the user $up
//but I would like to check if his password matches and then get his information
}
}
}
我查看了其他人的某种身份验证脚本,它们通过ldap_bind
检查信息,但是我只能与管理员用户连接。
我相信您需要做的唯一更改是:
if ($bind = ldap_bind($ldap, "$up@dejan.local", $pw)){
这将使请求本地化到特定域。 使用Active Directory(有些不同,怪怪的Kerberos),您必须提供登录上下文。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.