Bluehost.com Web Hosting $6.95

Problems with login form

This is a discussion on Problems with login form within the alt.comp.lang.php forums, part of the PHP Programming Forums category; Hi Has anyone experienced this problem before? I created a simple login page using an HTML form. PHP check the ...


Go Back   Usenet Forums > PHP Programming Forums > alt.comp.lang.php

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 01-01-2007
Nakkie
 
Posts: n/a
Default Problems with login form

Hi

Has anyone experienced this problem before?
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?


Reply With Quote
  #2 (permalink)  
Old 01-02-2007
Gleep
 
Posts: n/a
Default Re: Problems with login form

On Mon, 1 Jan 2007 14:24:34 +0200, "Nakkie" <nakkie@telkomsa.net> wrote:

>Hi
>
>Has anyone experienced this problem before?
>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?
>



you need to validate that the fields are filled out first, if not - don't do any processing

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

if($_POST['Submit']) {
if(empty($username) OR empty($password)) {
$errorNote = "Username and Password are required";
exit;
} else {
test the username and password
}
} // end of submit


// somewhere on the page
echo $errorNote;

this will give you the general idea, adapt to your needs.


Reply With Quote
  #3 (permalink)  
Old 01-02-2007
Nakkie
 
Posts: n/a
Default Re: Problems with login form


"Gleep" <Gleep@Gleep.com> wrote in message
news:ckmjp25259jnmvksbc92qufljc61f4k9tm@4ax.com...
> On Mon, 1 Jan 2007 14:24:34 +0200, "Nakkie" <nakkie@telkomsa.net> wrote:
>
>>Hi
>>
>>Has anyone experienced this problem before?
>>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?
>>

>
>
> you need to validate that the fields are filled out first, if not - don't
> do any processing
>
> $username = $_POST['username'];
> $password = $_POST['password'];
>
> if($_POST['Submit']) {
> if(empty($username) OR empty($password)) {
> $errorNote = "Username and Password are required";
> exit;
> } else {
> test the username and password
> }
> } // end of submit
>
>
> // somewhere on the page
> echo $errorNote;
>
> this will give you the general idea, adapt to your needs.
>
>


Thanx a mil - I'll try it out


Reply With Quote
  #4 (permalink)  
Old 01-02-2007
Ric
 
Posts: n/a
Default Re: Problems with login form

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
Reply With Quote
  #5 (permalink)  
Old 01-04-2007
Nakkie
 
Posts: n/a
Default Re: Problems with login form


"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) {

?>


Reply With Quote
  #6 (permalink)  
Old 01-05-2007
Richard Schneidt
 
Posts: n/a
Default Re: Problems with login form

Nakkie schrieb:
> "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


What do you expect from that code?

check_pass is never called so whatever you do you don't check any
password. The code below doesn't have all the info or your code is not
complete.

>
> <?
> $password_file = "/pass.txt";
> $username = $_POST['login'];
> $password = $_POST['password'];
> if($_POST['checkpass']) {


You need to make sure these params have been submitted otherwise you
will get warnings:

e.g. isset($_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 {
> }
> }
>
>

where do you call this function?

> 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) {


where is this function called?

>
> ?>
>
>

Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT +1. The time now is 06:29 PM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0