Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Attempt to connect to LDAP server
- $ldapconn = ldap_connect($ldaphost, $ldapport)
- or exit("Unable to connect to authentication server.");
- // Need to manually set to LDAPv3
- ldap_set_option($ldapconn, LDAP_OPT_PROTOCOL_VERSION, 3);
- // Bind against the directory using the BINDDN
- $ldapbind = ldap_bind($ldapconn, $binddn, $bindpw)
- or exit("Failed to bind to authentication server.");
- // Search for matching user
- $filter = "(&(objectClass=inetOrgPerson)(uid=$username))";
- $searchresult = ldap_search($ldapconn, $basedn, $filter);
- //Get the first matching user (there can't be duplicates so that's OK)
- $info = ldap_first_entry($ldapconn, $searchresult);
- // Get the DN of the matching user
- $dn = ldap_get_dn($ldapconn, $info);
- //Attempt to bind as the user
- $ldapuserbind = ldap_bind($ldapconn, $dn, $escaped_password)
- or exit("ERROR: Unable to log user in.");
- // Gets multi-dimensional array containing all user attributes
- $userinfo = ldap_get_attributes($ldapconn, $info);
- $username = ldap_get_values($ldapconn, $info, "uid");
- $firstname = ldap_get_values($ldapconn, $info, "givenName");
- $lastname = ldap_get_values($ldapconn, $info, "sn");
- $email = ldap_get_values($ldapconn, $info, "mail");
- $password = ldap_get_values($ldapconn, $info, "userPassword");
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement