I have a login form in which i have a username, password and a remember me radio button option. Now I want it so that when I've signed out from home page and I try again to login then without asking for a username and password I get logged in because I am going to store the username and password values into cookie.
I wrote code on password_match. php page(action page of login page)
Now when starting, when I enter username and password and if these are right show a cookie must have been set and if now I am signed out and try the same sign in form, as according to me it should retrive cookie but nothing happining here. I am not able to implement it. Where am I going wrong?
I wrote code on password_match. php page(action page of login page)
Code:
$con=mysql_connect("localhost","root","");
if(!$con)
{
die('Could Not Connect:'.mysql_error());
}
mysql_select_db("tcs",$con);
if(isset($_COOKIE['cookname']) && isset($_COOKIE['cookpass']))
{
$usr = $_COOKIE['cookname'];
$pwd = $_COOKIE['cookpass'];
$pwd=hash('sha1',$_POST['password']);
}
else
{
$usr=$_POST["username"];
$pwd=hash('sha1',$_POST['password']);
}
</code>
Through this code I am checking is there any cookie with cookname and cookpassword which contain username and password. If no cookie is found with this name then retrieve username and password from textboxes directly, if the user enters them.
Now the code which I am going to write will set a cookie if username and password exists:
<code>
if ($result) { $row=mysql_fetch_array($result);
if (($row["Username"]==$usr) && ($row["Password"]==$pwd))
{
if(isset($_POST['remember']))
{
setcookie("cookname", $row['Username'], time()+60*60*24*100, "/");
setcookie("cookpass", $row['Password'], time()+60*60*24*100, "/");
}
$_SESSION['employee']['id']=$row['User Id'];
$_SESSION['employee']['username']=$row['Username'];
header ("Location: home_page.php");
}
Comment