Created
April 18, 2013 13:41
-
-
Save tai2/5412758 to your computer and use it in GitHub Desktop.
LDAP authentication.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| $conn = ldap_connect($host, $port); | |
| if ($conn) { | |
| echo "ldap connected\n"; | |
| if (ldap_bind($conn, $bind_dn, $password)) { | |
| echo "bind suceeded\n"; | |
| $search_result = ldap_search($conn, $base_dn, "(&(objectClass=person)(uid={$username}))"); | |
| if ($search_result) { | |
| echo "search suceeded\n"; | |
| $entries = ldap_get_entries($conn, $search_result); | |
| if (0 < count($entries)) { | |
| $user_dn = $entries[0]['dn']; | |
| if (ldap_bind($conn, $user_dn, $userpwd)) { | |
| echo "user authentication succeeded\n"; | |
| } else { | |
| echo "user authentication failed\n"; | |
| } | |
| } | |
| } | |
| } else { | |
| echo "bind failed\n"; | |
| } | |
| ldap_close($conn); | |
| } else { | |
| echo "connect faild\n"; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment