pastebin - collaborative debugging

pastebin is a collaborative debugging tool allowing you to share and modify code snippets while chatting on IRC, IM or a message board.

This site is developed to XHTML and CSS2 W3C standards. If you see this paragraph, your browser does not support those standards and you need to upgrade. Visit WaSP for a variety of options.

PHP ZTDev Pastebin View Help

Posted by Anonymous on Thu 28th May 07:08 (modification of post by view diff)
download | new post

  1. <?php
  2.  
  3. /* Multi-purpose Active Directory Authentication front-end
  4. Written by Mark Cutting. Designed to be a portal for all custom
  5. written applications. This function is to be executed after
  6. the user enters their username and password. All subsequent
  7. pages will use an include function to call checkauth.php
  8. This prevents any malicious users attempting to bypass
  9. the login prompt by chosing a page from the directory */
  10.  
  11. //Temporarily disable error reporting
  12. ini_set('error_reporting', E_NONE);
  13.  
  14. //Temporarily disable all warnings
  15. ini_set('display_errors', 0);
  16.  
  17. // Test to see which browser is being used
  18. $_SERVER['HTTP_USER_AGENT'];
  19.  
  20.         $browsers = array(
  21. //            'MSIE',
  22.                 'Chrome',
  23.                 );
  24.  
  25. // Loop through browser detection. If there is an unsupported browser, advise, and kill script
  26.         foreach ($browsers as $b) {
  27.                 if (stristr($_SERVER['HTTP_USER_AGENT'], $b) !== FALSE) {
  28. echo '<strong><font color=red>FAILED: </strong>'.$_SERVER['HTTP_USER_AGENT']; echo '<br></strong>';
  29. die ('<font color=black>Sorry, this application is not supported by this browser.');
  30. } else {
  31.  
  32. }
  33. }
  34. // start the session
  35.  
  36. /*simple checking of the data*/
  37. if (!$_POST['username'])
  38. {
  39. die('<b><font color=red>The username cannot be blank</b>');
  40. }
  41. if (!$_POST['password'] )
  42. {
  43. die('<b><font color=red>The password cannot be blank</b>');
  44. }
  45.  
  46. ldap_set_option($conn, LDAP_OPT_PROTOCOL_VERSION, 3);
  47. $basedn = ''; //AD suffix goes here, for example, "dc=sales, dc=microsoft, dc=com"
  48. $domain = ''; // Domain suffix goes here, for example "sales.microsoft.com"
  49. $username = $_POST['username']; // Username provided in form
  50. $password = $_POST['password']; // Password provided in form
  51. $dusername = $username . "@" . $domain; // Add $domain variable to username to make FQDN
  52.  
  53. $conn = ldap_connect("") // AD server goes here as IP Address or FQDN
  54.    or die("Could not connect to Active Directory!");
  55.  
  56. if ($conn) {
  57.  
  58.  
  59.    // binding to ldap server
  60.    $bind = ldap_bind($conn, $dusername, $password);
  61.  
  62. /* Ideally, we want to secure the login session to that not just anyone in AD can
  63. gain access to our portal session. We can do this by using an explicit define
  64. that looks for particular login ID's. If these do not matchm the session is
  65. stopped, and a denied message displayed to the user */
  66.  
  67. /* This section is broken, so disabling for now - should really be an array for multiples
  68.    if (!($dusername == ''. "@". $domain)) die ("<font color=red><b>You are not permitted to logon to this section</b>");
  69.    if (!($dusername == ''. "@". $domain)) die ("<font color=red><b>You are not permitted to logon to this section</b>");
  70.    if (!($dusername == ''. "@". $domain)) die ("<font color=red><b>You are not permitted to logon to this section</b>");
  71.    if (!($dusername == ''. "@". $domain)) die ("<font color=red><b>You are not permitted to logon to this section</b>");
  72. */
  73.  
  74.    // verify binding
  75.    if ($bind) {
  76.    header("Location: main.php");
  77.    
  78.    $_SESSION['username'] = $_POST['username']';
  79.    } else {
  80.        echo "<font color=red><b>Invalid User Name/Password Please Retype</b>";
  81.    }
  82. }
  83. ?>

Submit a correction or amendment below (click here to make a fresh posting)
After submitting an amendment, you'll be able to view the differences between the old and new posts easily.

Syntax highlighting:

To highlight particular lines, prefix each line with @@


Remember me