Advertisement
Guest User

Untitled

a guest
Jul 6th, 2016
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.94 KB | None | 0 0
  1. private function dologinWithPostData()
  2. {
  3.  
  4. if (empty($_POST['user_name'])) {
  5. $this->errors[] = "Username field was empty.";
  6. } elseif (empty($_POST['user_password'])) {
  7. $this->errors[] = "Password field was empty.";
  8. } elseif (!empty($_POST['user_name']) && !empty($_POST['user_password'])) {
  9. //ldap_set_option(NULL, LDAP_OPT_DEBUG_LEVEL, 7);
  10.  
  11. $username = $_POST['user_name'];
  12. $password = $_POST['user_password'];
  13. $adServer = "ldaps://The Address";
  14.  
  15. $ldap = ldap_connect($adServer);
  16.  
  17. $ldaprdn = 'MYDN.net' . "\" . $username;
  18.  
  19. ldap_set_option($ldap, LDAP_OPT_PROTOCOL_VERSION, 3);
  20. ldap_set_option($ldap, LDAP_OPT_REFERRALS, 0);
  21.  
  22. $bind = @ldap_bind($ldap, $ldaprdn, $password);
  23.  
  24. if ($bind) {
  25.  
  26. // Get user info by there account login
  27. $filter="(sAMAccountName=$username)";
  28. $result = ldap_search($ldap,"dc=MYDC,dc=NET",$filter);
  29. ldap_sort($ldap,$result,"sn");
  30. $info = ldap_get_entries($ldap, $result);
  31.  
  32.  
  33. @ldap_close($ldap);
  34.  
  35. $fullName = $info[0]["displayname"][0];
  36. $dn = $info[0]["dn"];
  37. $groups = array();
  38.  
  39. if (array_key_exists("memberof", $info[0])){
  40. $x = $info[0]["memberof"];
  41. $groups = array();
  42.  
  43. foreach ($x as $key){
  44. if(strlen($key)>1){
  45. array_push($groups, $this->get_string_between($key, "CN=", ",") );
  46. }
  47. }
  48. }
  49.  
  50. @ldap_close($ldap);
  51. $_SESSION['userID'] = bin2hex($info[0]["objectguid"][0]);
  52. $_SESSION['fullName'] = $fullName;
  53. $_SESSION['userGroups'] = $groups;
  54. $_SESSION['loggedOnStatus'] = "1";
  55.  
  56. if(in_array('Dept_Directors', $groups)){
  57. $_SESSION['userLevel'] = 10;
  58. }elseif(in_array('Dept_Admin', $groups)){
  59. $_SESSION['userLevel'] = 7;
  60. }else{
  61. $_SESSION['userLevel'] = 0;
  62. }
  63.  
  64. if (strpos($dn, 'OU=MYOU') !== false) {
  65. $_SESSION['userType'] = 2;
  66. }elseif(strpos($dn, 'OU=MYOU') !== false){
  67. $_SESSION['userType'] = 1;
  68. }
  69.  
  70.  
  71.  
  72.  
  73. if($this->checkUserProfileExsists() == false){
  74. if(!($this->createUserProfile())){
  75. $msg="Error Creating User Profile ";
  76. echo $msg;
  77. }
  78. }
  79. } else {
  80. @ldap_close($ldap);
  81. $this->errors[] = "Wrong Username or Password";
  82.  
  83. }
  84.  
  85. } else {
  86. @ldap_close($ldap);
  87. echo "Wrong password. Try again.";
  88. }
  89. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement