Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function login($user, $md5_password, $first_time = false, $password = "")
- {
- global $dbconn, $main;
- $user = $dbconn -> escape($user);
- $username = $dbconn -> escape($user);
- // LDAP settings.
- $host = "ldaps://{URL}";
- $port = 636;
- $admindn = "{DN}";
- $adminpass = "{PASSWORD};
- $basedn = "{CONTEXT}";
- $error = "";
- $auth = false;
- // Try to connect to the LDAP server.
- $ldapconn = ldap_connect($host, $port) or die("Could not authenticate LDAP username and password");
- if (ldap_bind($ldapconn, $admindn, $adminpass))
- {
- // Retrieve the user's LDAP distinguished name.
- $results = ldap_search($ldapconn, $basedn, "cn=$username");
- $info = ldap_get_entries($ldapconn, $results);
- $ldapuser->dn = $info[0]["dn"];
- // Attempt to bind with the user's dn and entered password.
- if (!empty($ldapuser->dn))
- {
- // Process login as normal.
- if (trim($password) != "")
- {
- $auth = ldap_bind($ldapconn, $ldapuser->dn, $password);
- }
- }
- }
- }
Add Comment
Please, Sign In to add comment