|
|
Posted by Nakkie on 01/04/07 16:34
"Ric" <antispam@randometry.com> wrote in message
news:endi5o$4dq$1@online.de...
> Nakkie schrieb:
>> Hi
>>
>> Has anyone experienced this problem before?
> No
>> I created a simple login page using an HTML form.
>> PHP check the username and password against a .txt file.
>> The authentication part is doing what it's supposed to do with both valid
>> and invalid details.
>> The problem comes in when I leave both fields blank and click the login
>> button - it authenticates...... and take me to the restircetd area....
>> I have created a password for a blank username as well as a space, but it
>> stil does the same.
>> Any idea how to fix this?
>>
>>
>
> Show us some code, login form + validation code + your text file.
> I'm not sure how you do this right not.
>
> --Ric
Below follows the code. I got it sorted using lines 3 - 8 thanx
<?
$password_file = "/pass.txt";
$username = $_POST['login'];
$password = $_POST['password'];
if($_POST['checkpass']) {
if(empty($username) OR empty($password)) {
echo "Username and Password is required.<br />Use your browser Back
button to try again";
exit;
} else {
}
}
function check_pass($login, $password) {
global $password_file;
if(!$fh = fopen($password_file, "r")) {die("<P>Could Not Open Password
File - Contact the Webmaster");}
$match = 0;
$password = md5($password);
while(!feof($fh)) {
$line = fgets($fh, 4096);
$user_pass = explode(":", $line);
if($user_pass[0] == $login) {
if(rtrim($user_pass[1]) == $password) {
$match = 1;
break;
}
}
}
if($match) {
return 1;
}
else {
return 0;
}
fclose($fh);
}
function print_login_form($login) {
?>
[Back to original message]
|