Creating a script that Authenticates users

From: JENNA (assertec_at_bigpond.com)
Date: 10/27/04

  • Next message: David Collantes: "V-webmail and Richard Heyes"
    Date: 26 Oct 2004 19:46:35 -0700
    
    

    Hi all,

    I'm having real problems trying to create an authentication script
    that works.

    I have a text file that lists usernames and passwords separated by a
    colon like this for a simple example:

    jenna:124
    fred:234
    harry:777
    etc.. etc

    I have saved this file as: Authorization.txt

    My php file actually reads like below but when I run it, it seems to
    only check the first username and password in the Authorization.txt
    (i.e jenna:124 in this case) and doesn't seem to check the rest. The
    php file gets the username and password that need to be authenticated
    from a html document.

    Does anyone have any code that will do this for me, as I've tried
    messing around with this for ages, and I'm not getting anywhere.

    Thanks so much for any help with this.
    Regards Jenna

    -------------------------

    <html>
    <head><H1></H1></head>
    <body>

    <?php

    $auth = false; //assumes the user is not authenticated
    $filename = 'Authorization.txt';
    $fp = fopen($filename, 'r');
    $file_contents = fread($fp, filesize( $filename ));
    fclose($fp);

    $_GET['Username']; //receives the username from the html document
    $_GET['Password']; //receives the password from the html document

    $ContentsArray = explode("\r\n", $file_contents);

    foreach($ContentsArray As $ArrayIndex)
    {
            list($UsernameInFile, $PasswordInFile) = explode(":",
    $ArrayIndex);
            if(($Username == "$PHP_AUTH_USER") && ($Password == "$PHP_AUTH_PW"))
            
            {
            $auth = true;
            break;
            }
    }
            
    if(! $auth)
    {
                echo 'You are unathorized;
                exit;
    }
    else
    {
               echo 'You are authorized!';
    }

    ?>

    </body>
    </html>


  • Next message: David Collantes: "V-webmail and Richard Heyes"

    Relevant Pages

    • Re: validating # sign in php
      ... enter and clicks on a image to find if that username is available. ... abc#123 php file is reading this value as abc ONLY which i do not want ... instead the php file ... value entered in the form in javascript as ...
      (comp.lang.php)
    • Re: encrypt php code?
      ... > stores a username and password. ... Is this file parsed as a php file? ... give it a .php extension ...
      (comp.lang.php)
    • problem with authentication routine
      ... The php file is in the same directory as the .htpasswd file and there is no ... .htaccess file. ... Basic realm="My Realm"') dialog pops up and asks for username and ...
      (comp.lang.php)
    • problem with authentication routine
      ... The php file is in the same directory as the .htpasswd file and there is no ... .htaccess file. ... Basic realm="My Realm"') dialog pops up and asks for username and ...
      (alt.php)