Guest User

Untitled

a guest
Mar 12th, 2018
49
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.54 KB | None | 0 0
  1. <?php
  2. if(isset($_POST['username']) && isset($_POST['password'])){
  3.  
  4. $adServer = "ldap://10.13.10.17";
  5.  
  6. $ldap = ldap_connect($adServer);
  7. $username = $_POST['username'];
  8. $password = $_POST['password'];
  9.  
  10. $ldaprdn = $username.'@scorpion.com';
  11.  
  12. ldap_set_option($ldap, LDAP_OPT_PROTOCOL_VERSION, 3);
  13. ldap_set_option($ldap, LDAP_OPT_REFERRALS, 0);
  14.  
  15. $bind = @ldap_bind($ldap, $ldaprdn, $password);
  16.  
  17.  
  18. if ($bind)
  19. {
  20. $filter="(sAMAccountName=$username)";
  21. $result = ldap_search($ldap,"dc=scorpion,dc=com",$filter);
  22. ldap_sort($ldap,$result,"sn");
  23. $info = ldap_get_entries($ldap, $result);
  24. for ($i=0; $i<$info["count"]; $i++)
  25. {
  26. if($info['count'] > 1)
  27. break;
  28. echo "<p>You are accessing <strong> ". $info[$i]["sn"][0] .", " . $info[$i]["givenname"][0] ."</strong><br /> (" . $info[$i]["samaccountname"][0] .")</p>\n";
  29. echo '<pre>';
  30. var_dump($info);
  31. echo '</pre>';
  32. $userDn = $info[$i]["distinguishedname"][0];
  33. }
  34. @ldap_close($ldap);
  35. }
  36. else
  37. {
  38. $msg = "Invalid email address / password";
  39. echo $msg;
  40. }
  41.  
  42. }else{
  43. ?>
  44. <form action="#" method="POST">
  45. <label for="username">Username: </label><input id="username" type="text" name="username" />
  46. <label for="password">Password: </label><input id="password" type="password" name="password" /> <input type="submit" name="submit" value="Submit" />
  47. </form>
  48. <?php } ?>
Add Comment
Please, Sign In to add comment