Re: [users@httpd] Form Login Script

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxxxxxxxxxxx
  "   from the digest: users-digest-unsubscribe@xxxxxxxxxxxxxxxx
For additional commands, e-mail: users-help@xxxxxxxxxxxxxxxx



[Index of Archives]     [Open SSH Users]     [Linux ACPI]     [Linux Kernel]     [Linux Laptop]     [Kernel Newbies]     [Security]     [Netfilter]     [Bugtraq]     [Squid]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Samba]     [Video 4 Linux]     [Device Mapper]

  Powered by Linux