+ Post New Thread
Results 1 to 4 of 4
Coding Thread, php - AD authentication in Coding and Web Development; Can anyone help? I'm trying (failing miserably!) to create a simple login page for our web-based school reports. It's a ...
  1. #1
    detjo's Avatar
    Join Date
    Feb 2008
    Posts
    356
    Thank Post
    13
    Thanked 47 Times in 39 Posts
    Rep Power
    31

    php - AD authentication

    Can anyone help?

    I'm trying (failing miserably!) to create a simple login page for our web-based school reports. It's a php/mysql setup.
    Basically, i'm trying to get the user to authenticate with AD, and on success go to page X else stay on login page, but my retard brain can't see how the code is meant to go together.

    I've tried a number of examples i found on the www but i always get problems with them. They either authenticate 'successfully' without even showing me the login box and redirect me straight to page 1 (suggesting the auth bit of code is running before i 'submit' ) or i get errors for undefined variables etc.

    it occurs to me as i write this that maybe it doesn't have to be php, just that's what i'm using.

    (BooHoo!)

  2. #2
    jamiess's Avatar
    Join Date
    Oct 2009
    Location
    Balsall Common
    Posts
    72
    Thank Post
    10
    Thanked 20 Times in 17 Posts
    Rep Power
    14
    Im, not really sure what your are asking for help with. However this is how I would do it:

    I would download this: adLDAP - LDAP Authentication with PHP for Active Directory

    I would have my login form POST the users data over to Login_process.php which would then authenticate the user and then redirect. I've knocked up a quick example.

    Login form -

    HTML Code:
    <!DOCTYPE html>
    <html lang="en">
    	<head>
    		<meta charset="utf-8">
    		<title></title>
    	</head>
    	<body>
    
    		<form action="login_process.php" method="POST">
    			<label for="username">Username:</label>
    			<input type="text" name="username" />
    			<label for="password ">Password:</label>
    			<input type="password" name="password" />
    		</form>
    
    	</body>
    </html>
    login_process.php

    PHP Code:
    <?php

    require_once('adldap.php');

    $username $_POST('username');
    $password $_POST('password');

    $adldap = new adLDAP();

    $authUser $adldap->user()->authenticate($username$password);
    if(
    $authUser == true)
    {
        
    header('Location: newpage.php');
    }
    else
    {
        
    header('Location: login.html');
    }
    You'll obviously want to sanitise the POST variables or detect if there empty and provide feedback to the user. I havent tested this code and I know that LDAP / AD can be a right pain to get right.

    Good Luck

    Jamie

  3. 2 Thanks to jamiess:

    detjo (5th December 2012), zag (5th December 2012)

  4. #3
    detjo's Avatar
    Join Date
    Feb 2008
    Posts
    356
    Thank Post
    13
    Thanked 47 Times in 39 Posts
    Rep Power
    31
    Thanks, Jamie. I'll give that a go

  5. #4
    detjo's Avatar
    Join Date
    Feb 2008
    Posts
    356
    Thank Post
    13
    Thanked 47 Times in 39 Posts
    Rep Power
    31
    Well I got it going in the end

    I tried your example but got an error about expecting a string, then i had a thought that i would also want to include a 'deny' on direct URLs if the user was not logged in - which i already had with the current (now old) log-in.

    When i started this project (over a year ago - it's now becoming version 2) the log-in was created by Dreamweaver as i knew zero about php, and it basically used a MySQL table to check user credentials. Dreamweaver also included the deny code on direct URLs too.
    So, the answer was to use adLDAP (thanks for that) and swap the old Dreamweaver bit of code that checked the MySQL table, for the adLDAP bit that verified the user against AD - and with a couple of session variable tweaks, would also allow me to keep the deny stuff too.

    And that's it. All up and running with AD authentication

SHARE:
+ Post New Thread

Similar Threads

  1. AD Authentication for the Cachepilot
    By Crowmanuk in forum Internet Related/Filtering/Firewall
    Replies: 1
    Last Post: 1st June 2010, 02:58 PM
  2. Replies: 17
    Last Post: 18th August 2008, 02:03 PM
  3. MediaWiki LDAP AD authentication
    By plexer in forum How do you do....it?
    Replies: 7
    Last Post: 22nd February 2007, 08:54 AM
  4. OS X AD Authentication
    By Ric_ in forum Mac
    Replies: 8
    Last Post: 29th August 2006, 02:13 PM
  5. Replies: 5
    Last Post: 28th June 2006, 06:15 PM

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •