Guest User

Untitled

a guest
May 22nd, 2018
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.02 KB | None | 0 0
  1. function login($user, $md5_password, $first_time = false, $password = "")
  2. {
  3. global $dbconn, $main;
  4.  
  5. $user = $dbconn -> escape($user);
  6. $username = $dbconn -> escape($user);
  7.  
  8. // LDAP settings.
  9. $host = "ldaps://{URL}";
  10. $port = 636;
  11. $admindn = "{DN}";
  12. $adminpass = "{PASSWORD};
  13. $basedn = "{CONTEXT}";
  14. $error = "";
  15.  
  16. $auth = false;
  17.  
  18. // Try to connect to the LDAP server.
  19. $ldapconn = ldap_connect($host, $port) or die("Could not authenticate LDAP username and password");
  20. if (ldap_bind($ldapconn, $admindn, $adminpass))
  21. {
  22. // Retrieve the user's LDAP distinguished name.
  23. $results = ldap_search($ldapconn, $basedn, "cn=$username");
  24. $info = ldap_get_entries($ldapconn, $results);
  25.  
  26. $ldapuser->dn = $info[0]["dn"];
  27.  
  28. // Attempt to bind with the user's dn and entered password.
  29. if (!empty($ldapuser->dn))
  30. {
  31. // Process login as normal.
  32. if (trim($password) != "")
  33. {
  34. $auth = ldap_bind($ldapconn, $ldapuser->dn, $password);
  35. }
  36. }
  37. }
  38. }
Add Comment
Please, Sign In to add comment