[users@httpd] Form Login Script

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

 



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';

}

?>

 


[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