Advertisement
Guest User

Untitled

a guest
Mar 1st, 2017
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.58 KB | None | 0 0
  1. <?php
  2. /**
  3. * Created by Joe of ExchangeCore.com
  4. */
  5. if(isset($_POST['username']) && isset($_POST['password'])){
  6.  
  7. $adServer = "isec.local";
  8.  
  9. $ldap = ldap_connect($adServer);
  10. $username = $_POST['username'];
  11. $password = $_POST['password'];
  12.  
  13. $ldaprdn = $username . '@' . 'isec.local';
  14.  
  15. ldap_set_option($ldap, LDAP_OPT_PROTOCOL_VERSION, 3);
  16. ldap_set_option($ldap, LDAP_OPT_REFERRALS, 0);
  17.  
  18. $bind = @ldap_bind($ldap, $ldaprdn, $password);
  19.  
  20.  
  21. if ($bind) {
  22. $filter="(sAMAccountName=$username)";
  23. $result = ldap_search($ldap,"dc=MYDOMAIN,dc=COM",$filter);
  24. ldap_sort($ldap,$result,"sn");
  25. $info = ldap_get_entries($ldap, $result);
  26. for ($i=0; $i<$info["count"]; $i++)
  27. {
  28. if($info['count'] > 1)
  29. break;
  30. echo "<p>You are accessing <strong> ". $info[$i]["sn"][0] .", " . $info[$i]["givenname"][0] ."</strong><br /> (" . $info[$i]["samaccountname"][0] .")</p>\n";
  31. echo '<pre>';
  32. var_dump($info);
  33. echo '</pre>';
  34. $userDn = $info[$i]["distinguishedname"][0];
  35. }
  36. @ldap_close($ldap);
  37. } else {
  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 } ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement