2011-07-31 100 views
1

我想驗證我創建的ldap服務器的againest。用戶密碼以散列形式存儲在ldap中。但是,當我嘗試訪問userPassword屬性時,它不存在。我必須以經理身份登錄。假設這在生產服務器上不是一個好主意。有沒有解決的辦法?openldap auththentication php5 - 比較密碼

回答

1

返回密碼字段沒有意義。您可以簡單地使用給定的憑據對LDAP服務器進行身份驗證。

看到該示例(參考這裏:http://php.net/manual/en/ref.ldap.php

<?php 

$user = 'bob'; 
$password = 'zhlob'; 
$host = 'myldap'; 
$domain = 'mydomain.ex'; 
$basedn = 'dc=mydomain,dc=ex'; 
$group = 'SomeGroup'; 

$ad = ldap_connect("ldap://{$host}.{$domain}") or die('Could not connect to LDAP server.'); 
ldap_set_option($ad, LDAP_OPT_PROTOCOL_VERSION, 3); 
ldap_set_option($ad, LDAP_OPT_REFERRALS, 0); 
@ldap_bind($ad, "{$user}@{$domain}", $password) or die('Could not bind to AD.'); 
$userdn = getDN($ad, $user, $basedn); 
if (checkGroupEx($ad, $userdn, getDN($ad, $group, $basedn))) { 
//if (checkGroup($ad, $userdn, getDN($ad, $group, $basedn))) { 
    echo "You're authorized as ".getCN($userdn); 
} else { 
    echo 'Authorization failed'; 
} 
ldap_unbind($ad); 
?>