PHP Password Problem.

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
fionaom87
Forum Commoner
Posts: 43
Joined: Mon Feb 02, 2009 10:44 am

PHP Password Problem.

Post 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 
} 
?>
        
 
cristiano
Forum Newbie
Posts: 18
Joined: Tue Jul 01, 2008 1:44 am

Re: PHP Password Problem.

Post by cristiano »

You have to use

Code: Select all

<input type="password">
if you want the password to be displayed as dots.
fionaom87
Forum Commoner
Posts: 43
Joined: Mon Feb 02, 2009 10:44 am

Re: PHP Password Problem.

Post 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.
killingbegin
Forum Newbie
Posts: 20
Joined: Sun Feb 08, 2009 5:07 am

Re: PHP Password Problem.

Post 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
Post Reply