开发者

Remember password by setting cookie

In my page I have one Remember Me checkbox. When I check this, I want to se my password in browser cookie. Is it possible? I have provided the statement as:

i开发者_高级运维f ($remember=='yes') {
    $this->load->helper('cookie');
    $cookie =array(
        'name'   => 'username',
        'value'  => $username,
        'expire' => '1209600'
    );
    $this->input->set_cookie($cookie);
}


The reason why you should never store an unencrypted password in a cookie is that cookie theft in that case will provide permanent access. If you store hashed version, then it might be possible to impersonate a user as long as the cookie is valid, but the attacker won't have any way to log back in again once that cookie is invalidated.

In short: never store plain text informations in the client's browser, always use (possibly salted and/or signed) hashes both for passwords and usernames.


Yes,

check out this site, Using Cookies in PHP - User Logon


    <?php 
    session_start(); 

    if(isset($_COOKIE['Joe2Torials'])) 
    { 
    $dbHost = 'localhost'; 
    $dbUser = 'root'; 
    $dbPass = ''; 
    $dbname = 'myshop'; 
    $username = $_COOKIE['Joe2Torials']['username']; 
    $password = $_COOKIE['Joe2Torials']['password']; 
    $db = mysql_connect($dbHost,$dbUser,$dbPass);
    mysql_select_db($dbname,$db);

    $query = "SELECT user, pass FROM login WHERE user = '$username' AND pass = '$password'"; 
    $result = mysql_query($query, $db); 

    if(mysql_num_rows($result)) 
    { 
    $_SESSION['loggedin'] = 1; 

    header('Location:admin.php'); 
    exit(); 
    } 
    } 
?> 

<form method="post" name="cookie" action="process.php"> 

<p><label for="username">Username : <input type="text" name="username" id="username" /></label></p> 
<p><label for="password">Password : <input type="password" name="password" id="password" /></label></p> 
<p><input type="checkbox" name="setcookie" value="setcookie" /> Remember Me</p> 

<p><input type="submit" name="submit" value="Submit" /> <input type="reset" name="reset" value="Reset" /></p> 
</form> 

<?php 
if (isset($_GET['error']) AND !empty($_GET['error'])) 
{ 
echo 'Invalid login data supplied. Please try again.'; 
} 
?>


ya it is posible .. u can remember your password by setting cookie See this videos

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜