Advertisement
Guest User

Untitled

a guest
Mar 24th, 2017
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.67 KB | None | 0 0
  1. <?php
  2.  
  3. session_start();
  4.  
  5. if(!empty($_POST['username']) && !empty($_POST['password'])){
  6.  
  7. $_SESSION['user'] = $_POST['username'];
  8.  
  9. $adServer = "***********";
  10.  
  11. $ldap = ldap_connect($adServer);
  12. $username = $_POST['username'];
  13. $password = $_POST['password'];
  14.  
  15.  
  16. $ldaprdn = $username.'@***********';
  17.  
  18. ldap_set_option($ldap, LDAP_OPT_PROTOCOL_VERSION, 3);
  19. ldap_set_option($ldap, LDAP_OPT_REFERRALS, 0);
  20.  
  21. $bind = @ldap_bind($ldap, $ldaprdn, $password);
  22.  
  23.  
  24. if ($bind)
  25. {
  26. $filter="(sAMAccountName=$username)";
  27. $result = ldap_search($ldap,"DC=***********,DC=com",$filter);
  28. ldap_sort($ldap,$result,"sn");
  29. $info = ldap_get_entries($ldap, $result);
  30. for ($i=0; $i<$info["count"]; $i++)
  31. {
  32. if($info['count'] > 1)
  33. break;
  34. if($info[$i]["department"][0] == IT) {
  35. $z="<p>Zalogowany <strong> ". $info[$i]["givenname"][0] ." " . $info[$i]["sn"][0] ."</strong>";
  36. }
  37. else {
  38. echo "Brak uprawnień do przeglądania zawartości. Żegnam. ";
  39. exit();
  40. }
  41.  
  42. }
  43. @ldap_close($ldap);
  44.  
  45.  
  46.  
  47. <html>
  48.  
  49. <?php echo $z ?>
  50.  
  51. </html>
  52.  
  53.  
  54.  
  55.  
  56. <?php
  57. }
  58.  
  59. else
  60. {
  61. $msg = "Nieprawidłowe dane. <a href=\"javascript:history.go(-1);\">Wstecz</a>.";
  62. echo $msg;
  63. }
  64.  
  65. }
  66.  
  67.  
  68.  
  69. else
  70. {
  71. ?>
  72.  
  73. <div>
  74. <form action="#" method="POST">
  75. <label for="username">Login: </label><input id="username" type="text" name="username" /> <br /> <br />
  76. <label for="password">Hasło: </label><input id="password" type="password" name="password" /> <br /> <br />
  77. <input type="submit" name="submit" value="Zaloguj" />
  78. </form>
  79. </div>
  80.  
  81. <?php
  82.  
  83. }
  84.  
  85. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement