#1
  1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2000
    Posts
    15
    Rep Power
    0
    I have used the following to enable user authentification ....however, I have noticed that it is possible to get around this by entering a wrong username and password until you reach the error page then press Back on the browser then press Forward and hey presto you are in. Have I made a mistake with the coding or is there a problem with using this method for user authentifcation.

    <?php
    require('../mydb.inc.php3');
    if (!isset($PHP_AUTH_USER)) {
    header('WWW-Authenticate: Basic realm="Dealer Administration Centre"');
    header('HTTP/1.0 401 Unauthorized');
    exit;
    } else if (isset($PHP_AUTH_USER)) {
    mysql_connect($hostname,$username,$password)
    or die ("Unable to connect to database.");
    mysql_select_db("$dbname")
    or die ("Unable to select database.");
    $sql = "SELECT * FROM $usertable WHERE uname='$PHP_AUTH_USER' and pword='$PHP_AUTH_PW'";
    $result = mysql_query($sql);
    $num = mysql_numrows($result);
    if ($num != "0") {
    ?>
    <? include "xxx.php3" ?>
    <?
    exit;
    } else {
    header('WWW-Authenticate: Basic realm="Dealers Administration Centre"');
    header('HTTP/1.0 401 Unauthorized');
    echo 'Authorization Required.';
    exit;
    }
    }
    ?>
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Aug 2000
    Location
    Indiana
    Posts
    614
    Rep Power
    16
    I've not had any problems with this code:
    <BLOCKQUOTE><font size="1" face="Verdana,Arial,Helvetica">code:</font><HR><pre>
    //Password Auth.
    function check_auth() {
    ##Global the Vars
    global $PHP_AUTH_USER,$PHP_AUTH_PW,$user_table;

    //MD5 the password for check
    $md5pass=md5($PHP_AUTH_PW);

    if(!isset($PHP_AUTH_USER)) {
    Header("WWW-Authenticate: Basic realm="LedNews"");
    Header("HTTP/1.0 401 Unauthorized");
    echo "Bad Username/Password.n";
    exit;
    } else {
    $query="SELECT * FROM $user_table WHERE username='$PHP_AUTH_USER' AND password='$md5pass'";
    $result=mysql_query($query);
    $number=mysql_num_rows($result);
    if($number<1) {
    Header("WWW-Authenticate: Basic realm="LedNews"");
    Header("HTTP/1.0 401 Unauthorized");
    echo "Bad Username/Password.n";
    exit;
    }#end if
    return;
    }
    }#end function
    [/code]
    (obviously it's got more stuff in there than just the basic function.)

    I used it in my news script that you can find here: http://www.ledscripts.com/free-php/lednews.html


    [This message has been edited by JonLed (edited September 30, 2000).]
  4. #3
  5. No Profile Picture
    Carpe Diem
    Guest
    Devshed Newbie (0 - 499 posts)
    A version of the above code is used for our admin scripts with slight mod's

    What you problem is is not faulty code but IE cacheing the page and the forward/back button showing the local version.

    Its just IE and no security risk.

    Darren http://www.php4hosting.com/
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Aug 2000
    Location
    Indiana
    Posts
    614
    Rep Power
    16
    Ah, that's a good point.

Similar Threads

  1. syntax error : identifer 'Hole'
    By bootrecker in forum C Programming
    Replies: 2
    Last Post: February 2nd, 2004, 08:08 AM
  2. How to implement a security sub-system?
    By simplesimple in forum Beginner Programming
    Replies: 2
    Last Post: January 24th, 2004, 04:33 PM
  3. Security hole maybe....
    By shadowarts in forum PHP Development
    Replies: 5
    Last Post: December 23rd, 2003, 03:37 PM
  4. security hole?
    By STEELV in forum ASP Programming
    Replies: 12
    Last Post: November 12th, 2003, 02:53 PM
  5. Garbled HTTP Submit
    By lustyx in forum Perl Programming
    Replies: 5
    Last Post: August 11th, 2003, 07:37 PM

IMN logo majestic logo threadwatch logo seochat tools logo