Advertisement
Guest User

Untitled

a guest
Sep 19th, 2017
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.29 KB | None | 0 0
  1. // Attempt to connect to LDAP server
  2. $ldapconn = ldap_connect($ldaphost, $ldapport)
  3. or exit("Unable to connect to authentication server.");
  4.  
  5. // Need to manually set to LDAPv3
  6. ldap_set_option($ldapconn, LDAP_OPT_PROTOCOL_VERSION, 3);
  7. // Bind against the directory using the BINDDN
  8. $ldapbind = ldap_bind($ldapconn, $binddn, $bindpw)
  9. or exit("Failed to bind to authentication server.");
  10.  
  11. // Search for matching user
  12. $filter = "(&(objectClass=inetOrgPerson)(uid=$username))";
  13. $searchresult = ldap_search($ldapconn, $basedn, $filter);
  14.  
  15. //Get the first matching user (there can't be duplicates so that's OK)
  16. $info = ldap_first_entry($ldapconn, $searchresult);
  17.  
  18. // Get the DN of the matching user
  19. $dn = ldap_get_dn($ldapconn, $info);
  20.  
  21. //Attempt to bind as the user
  22. $ldapuserbind = ldap_bind($ldapconn, $dn, $escaped_password)
  23. or exit("ERROR: Unable to log user in.");
  24.  
  25. // Gets multi-dimensional array containing all user attributes
  26. $userinfo = ldap_get_attributes($ldapconn, $info);
  27.  
  28. $username = ldap_get_values($ldapconn, $info, "uid");
  29. $firstname = ldap_get_values($ldapconn, $info, "givenName");
  30. $lastname = ldap_get_values($ldapconn, $info, "sn");
  31. $email = ldap_get_values($ldapconn, $info, "mail");
  32. $password = ldap_get_values($ldapconn, $info, "userPassword");
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement