通过设置cookie记住密码

发布于 2024-11-09 07:35:03 字数 339 浏览 0 评论 0原文

在我的页面中,我有一个“记住我”复选框。当我检查这个时,我想在浏览器 cookie 中设置我的密码。是否可以? 我提供的声明如下:

if ($remember=='yes') {
    $this->load->helper('cookie');
    $cookie =array(
        'name'   => 'username',
        'value'  => $username,
        'expire' => '1209600'
    );
    $this->input->set_cookie($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:

if ($remember=='yes') {
    $this->load->helper('cookie');
    $cookie =array(
        'name'   => 'username',
        'value'  => $username,
        'expire' => '1209600'
    );
    $this->input->set_cookie($cookie);
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

愛放△進行李 2024-11-16 07:35:04

永远不要在 cookie 中存储未加密的密码的原因是,在这种情况下,cookie 盗窃将提供永久访问权限。如果您存储散列版本,那么只要 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.

葬心 2024-11-16 07:35:04

是的,

请查看此网站,在 PHP 中使用 Cookie - 用户登录

Yes,

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

夏花。依旧 2024-11-16 07:35:04
    <?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.'; 
} 
?>
    <?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.'; 
} 
?>
森林散布 2024-11-16 07:35:04

是的,这是可能的..您可以通过设置cookie来记住您的密码
观看此视频

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文