Page 1 of 1

PHP Password Problem.

Posted: Sun Feb 15, 2009 9:51 am
by fionaom87
Hey i am trying to do a basic login, i know its not the most secure but i dont need it to be for what i am doing.
1. My first prob is when you are typing in the password it is appearing to the user.... i want it hidden, i do have <input type="hidden"> but doesnt seem to be working.
2. if you enter in the incorrect password it still goes onto the next page no matter what u type in.

Any help would be great.
Thanks
F :D



Code: Select all

 
<h1> Administration Log in </h1>
    
 
    <div id="box2" align="center">
 
    <?php error_reporting (E_ALL ^ E_NOTICE); ?>        
    
    
    <?php 
$form_posted=$_POST['form_posted']; 
if ($form_posted==1) 
{ 
$user=$_POST['user']; 
$pass=$_POST['pass']; 
 
 
if (($user=="fom") && ($pass=="123")) 
 
{ 
Echo "Login Successful"; 
echo ""; 
} 
 
else 
{ 
?> 
 
 
 
 
 
<form action="form.php" METHOD="POST" onsubmit="return validate_form(this)" > 
<table> 
<tr> 
<td colspan=2> Login Details Incorrect Please try again</td> 
</tr> 
<tr> 
<td><label>Username</label></td> 
<td> <input name="user" /></td> 
</tr> 
<tr> 
<td><label>Password</label></td> 
<td> <input name="pass"/></td> 
<td> <input type="hidden" name="form_posted" value="1"/></td> 
</tr> 
 
<tr> 
<td><INPUT class="button" name="submit" TYPE="submit" value="Submit"></td> 
</tr> 
 
</table></form> </body></html> 
<?php 
} 
 
} 
else 
 
{ 
?> 
 
<form action="reports.php" METHOD="POST" onsubmit="return validate_form(this)"> 
<table><tr> 
<td><label>Username</label></td> 
<td> <input name="user" /></td> 
</tr> 
<tr> 
<td><label>Password</label></td> 
<td> <input name="pass"/></td> 
<td> <input type="hidden" name="form_posted" value="1"/></td> 
</tr> 
 
<tr> 
<td><INPUT class="button" name="submit" TYPE="submit" value="Submit"></td> 
</tr> 
 
</table></form> </body></html> 
 
<?php 
} 
?>
        
 

Re: PHP Password Problem.

Posted: Sun Feb 15, 2009 11:53 am
by cristiano
You have to use

Code: Select all

<input type="password">
if you want the password to be displayed as dots.

Re: PHP Password Problem.

Posted: Sun Feb 15, 2009 1:44 pm
by fionaom87
ya thanks that solved one of my prbs.
Any idea about my 2nd one...

it doesnt seem to recognise the php password in the code. its letting me type in any password and going onto the next page.

Re: PHP Password Problem.

Posted: Sun Feb 15, 2009 2:44 pm
by killingbegin
Try that

Code: Select all

 
 <?php
 
if (!$_POST['submit']) // if he didnt pressed submit
      {
           header("Location:Yourform.php");
      }  
else 
      {
           $user=$_POST['user'];
           $pass=$_POST['pass']; 
      }
 
 
if ($user=="fom" AND $pass=="123")
 
{
 Echo "Login Successful";
}
 
else
 {
      header("Location:Yourform.php");
}
 
 

Its better to make 2 pages one for the form onother for the script
else in your action form you myst call php_self to refresh and post your data in the same page