Jump to content

how to set remind me function in login form


Tje

Recommended Posts

Hi,

My login form is running correctly.i want to add remind me function.please help me.

<form class="form-signin" role="form" id="form1" method="post" action="log.php">
 <h2 class="form-signin-heading text-center bluetxt">Sign In</h2>
<input type="text" id="email1" class="form-control" name="email1" placeholder="Email address"   autofocus /><br />
<input type="text" id="pwd1" class="form-control" name="pwd1" placeholder="Password" value=""/><br/>
<label class="checkbox">
          <input type="checkbox" value="remember" name="remember"> Remember me
        </label>
<input type="submit" value="Login" onclick="ValidationLog()" style="color:#FFF;" class="btn btn-lg btn-primary btn-block"/>
</form>
<?php

$mail = $_POST['email1'];
$pwd  = $_POST['pwd1'];

$con = mysql_connect("localhost","root","");
if(!$con)
{
	die('Could not connect:'.mysql_error());
}
mysql_select_db("biz",$con);
if((($mail)&&($pwd))==""){
header( 'Location:index.php' );
}else{

$result = mysql_query("SELECT mail,pw FROM reg WHERE mail = '$mail' AND pw = '$pwd'");
$num_rows = mysql_num_rows($result);
mysql_close($con);
if($num_rows == 0)
{

}
else{
header( 'Location:user/' );

}
}

?>

Hi there, Tje

On the login form I have changed the type of the password input box from text to password, this hides the password when the user types it.

Login Form:

<form class="form-signin" role="form" id="form1" method="post" action="log.php">
 <h2 class="form-signin-heading text-center bluetxt">Sign In</h2>
<input type="text" id="email1" class="form-control" name="email1" placeholder="Email address"   autofocus <?php
		  if(isset($_COOKIE['username']))
		  {
		  echo " value=\"".$_COOKIE['username']."\"";
		  }
		  ?> /><br />
<input type="password" id="pwd1" class="form-control" name="pwd1" placeholder="Password" value=""/><br/>
<label class="checkbox">
          <input type="checkbox" value="remember" name="remember"
		  <?php
		  if(isset($_COOKIE['remember']))
		  {
		  if($_COOKIE['remember'] == "remember")
		  {
		  echo " checked=\"checked\"";
		  }
		  }
		  ?>> Remember me
        </label>
<input type="submit" value="Login" onclick="ValidationLog()" style="color:#FFF;" class="btn btn-lg btn-primary btn-block"/>
</form>

PHP Code:

<?php

$mail = $_POST['email1'];
$pwd  = $_POST['pwd1'];
$remember  = $_POST['remember'];

$con = mysql_connect("localhost","root","");
if(!$con)
{
	die('Could not connect:'.mysql_error());
}
mysql_select_db("biz",$con);
if((($mail)&&($pwd))==""){
header( 'Location: index.php' );
}else{

$result = mysql_query("SELECT mail,pw FROM reg WHERE mail = '$mail' AND pw = '$pwd'");
$num_rows = mysql_num_rows($result);
mysql_close($con);
if($num_rows == 0)
{

}
else{
header( 'Location: user/' );

if($remember == "remember")
{
setcookie("remember", $remember, time()+3600);
setcookie("username", $mail, time()+3600);
}
}
}

?>

I know you asked for the login form to remember the password for 1 hour, this is not really recommended if the user uses a shared computer as anyone with physical access to the computer can access the users account.

Also in the PHP code, you might want to hash or salt the user's password to protect it in the database. This link might help on password hashing: http://php.net/manual/en/faq.passwords.php

You might want to add some SQL injection prevention (maybe use mysql_real_escape_string()). This link might help on SQL Injection: http://php.net/manual/en/security.database.sql-injection.php

 

Hope this helps.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.