URL: https://www.overclockers.at/coding-stuff/ldap_passwortabfrage_mit_php_155826/page_1 - zur Vollversion wechseln!
moin moin.
ich möcht auf einen ldap-server mittels php zugreifen, einen user herauspicken und abfragen ob das eingegebene passwort korrekt ist.
bis zum herauspicken bin ich gekommen, es schaut jetzt so aus:
Code: PHP<?php include 'ldapconfig.php'; $user=$_REQUEST["user"]; $pw=$_REQUEST["pw"]; $ldap_link=ldap_connect($ldap_host, $ldap_port); $bind=ldap_bind($ldap_link); ldap_search($ldap_link, $root_dn, "uid=$user"); //Jetzt hab ich den user, aber wie frag ich ob sein pw passt?? ?>
mein lösungsweg:
Code: PHP$userid = $_POST['userid']; $pass = $_POST['password']; if ($pass == "") { echo ("No Password!<p>You will be redirected in 5 sec."); die ("<meta http-equiv='refresh' content='5; URL=./authtest.html'>"); } echo "<h1>LDAP Authentification for " . $userid . "</h1><p>"; $ldap_link = ldap_connect($server); if(!ldap_link) { die ("connection error!"); } $bind = ldap_bind($ldap_link); if(!$bind) { die ("bind error!"); } $base_dn = <steht in der angabe>; $result = ldap_search($ldap_link, $base_dn, "uid=$userid"); $info = ldap_get_entries($ldap_link, $result); if(!$result) { die ("anonymous search failed"); } if ($info["count"] == 0) { die ("User unknown"); } if ($info["count"] > 1) { die ("More than one such user - report to administrator"); } $user_dn = $info[0]["dn"]; $bind = @ldap_bind($ldap_link, $user_dn, $pass); if (!$bind) { die ("bind failed, wrong password!"); } echo "LDAP Authentification granted!"; ldap_close($ldap_link);
oukeh, danke. des geht als solved markieren bitte.
Zitat von prayerslayeroukeh, danke. des gehtals solved markieren bitte.
overclockers.at v4.thecommunity
© all rights reserved by overclockers.at 2000-2025