httpd-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Boysenberry Payne <boysenbe...@humaniteque.com>
Subject Re: [users@httpd] Form Login Script
Date Wed, 28 Dec 2005 01:48:20 GMT
Try:

<?php

session_start();

function response( $text ) {
	echo $text;
	return;
}


$bad_user = "Invalid User Name";
$bad_pass = "Invalid Password";
$good_log = "Valid User.  Login Successful";

$usr = $_POST['username'];
$pass = $_POST['password'];

$valid_match = "/([a-z0-9-_])+/i";

if( !preg_match( $valid_match, $usr ) ) {
	return response( $bad_user );
  } elseif( !preg_match( $valid_match, $pass ) ) {
	 return response( $bad_pass );
  }

$users = file_get_contents( "users.txt" );
$results = array();
$valid_match = "/($usr):($pass)?/";
if( preg_match( $valid_match, $users, $results ) ) {
	if( !$results[ 2 ] ) {
		return response( $bad_pass );
	} else {
		return response( $good_log );
	}
  } else {
	return response( $bad_user );
  }
?>


Boysenberry

boysenberrys.com | habitatlife.com | selfgnosis.com

On Dec 27, 2005, at 6:55 PM, Christopher Deeley wrote:

> I am trying to use the following script to verify my users against a 
> text file where each line is in the format username:password.
>  
> This is my script below. It worked fine until I started adding more 
> users to the text file and it wouldn't recognise them. It will only 
> show as a valid user if it matches the last entry in the text file.
>  
>
> <?PHP
> session_start();
> $usr = $_POST['username'];
> $pass = $_POST['password'];
>
> $filename = 'users.txt';
> $fp = fopen( $filename, 'r' );
> $file_contents = fread( $fp, filesize( $filename ) );
> fclose( $fp );
> $lines = explode ( "\n", $file_contents );
> foreach ( $lines as $line ){
> list( $username, $password ) = explode( ':', $line );
> }
>
> if($username !== $usr){
> echo 'invalid username';
> die;
> }
>
> if ( ( $usr == $username ) &&
>              ( $pass == $password ) ) {
> echo 'Valid User. Login Successful';
> }
> else{
> echo 'Invalid Password';
>
> }
>
> ?>
>
>  

---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
   "   from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org


Mime
View raw message