Advertisement
Guest User

Untitled

a guest
Mar 24th, 2017
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.73 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. <a href="logout.php" style="text-decoration:none;">Wyloguj</a>
  52.  
  53. </html>
  54.  
  55.  
  56.  
  57.  
  58. <?php
  59. }
  60.  
  61. else
  62. {
  63. $msg = "Nieprawidłowe dane. <a href=\"javascript:history.go(-1);\">Wstecz</a>.";
  64. echo $msg;
  65. }
  66.  
  67. }
  68.  
  69.  
  70.  
  71. else
  72. {
  73. ?>
  74.  
  75. <div>
  76. <form action="#" method="POST">
  77. <label for="username">Login: </label><input id="username" type="text" name="username" /> <br /> <br />
  78. <label for="password">Hasło: </label><input id="password" type="password" name="password" /> <br /> <br />
  79. <input type="submit" name="submit" value="Zaloguj" />
  80. </form>
  81. </div>
  82.  
  83. <?php
  84.  
  85. }
  86.  
  87. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement