Advertisement
Guest User

Untitled

a guest
Jul 22nd, 2017
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.38 KB | None | 0 0
  1. <?php
  2.  
  3. if(isset($_POST['username']) && isset($_POST['password'])){
  4.  
  5. $adServer = "ldap://WIN-OLN6KSATODL.sena.com";
  6.  
  7. $ldap = ldap_connect($adServer);
  8. $username = $_POST['username'];
  9. $password = $_POST['password'];
  10.  
  11. $ldaprdn = 'sena' . "\" . $username;
  12.  
  13. ldap_set_option($ldap, LDAP_OPT_PROTOCOL_VERSION, 3);
  14. ldap_set_option($ldap, LDAP_OPT_REFERRALS, 0);
  15.  
  16. $bind = @ldap_bind($ldap, $ldaprdn, $password);
  17.  
  18.  
  19. if ($bind) {
  20. $filter="(sAMAccountName=$username)";
  21. $result = ldap_search($ldap,"dc=sena,dc=com",$filter);
  22. ldap_sort($ldap,$result,"389");
  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. } else {
  36. $msg = "Invalid email address / password";
  37. echo $msg;
  38. }
  39.  
  40. }else{
  41. ?>
  42. <form action="#" method="POST">
  43. <label for="username">Username: </label><input id="username" type="text" name="username" />
  44. <label for="password">Password: </label><input id="password" type="password" name="password" /> <input type="submit" name="submit" value="Submit" />
  45. </form>
  46. <?php } ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement