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 ...
|
|||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
|
|||
|
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? |
|
|||
|
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. |
|
|||
|
"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 |
|
|||
|
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 |
|
|||
|
"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) { ?> |
|
|||
|
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? > > ?> > > |