【问题标题】:Encode password using php shall and decode it in cookie使用 php 编码密码并在 cookie 中解码
【发布时间】:2016-05-01 07:07:34
【问题描述】:

我想记住用户名和密码。 当检查 cookie 将设置和散列密码但在密码字段中重新调整散列密码时,它也会显示散列值 这是我的编码和解码代码,请问有人可以提供更好的解决方案吗?

I use this to remember password
<?php
if($_POST['remember']) {
$remember_user = trim($_POST['username']);
$remember_pass = trim($_POST['password']);

$salt = "@g26jQsG&nh*&#8v";
$password_hash =  sha1($remember_pass.$salt);

setcookie('remember_user', $remember_user, $year);
setcookie('remember_pass', $password_hash, $year);


                $cookie_name = 'siteAuth';
        $cookie_time = time() - 100;
       $password_hash =  sha1($remember_pass.$salt);
   setcookie ($cookie_name, 'usr='.$remember_user.'&hash='.$password_hash, time() + $cookie_time);



}
else if(!$_POST['remember']) {
    if(isset($_COOKIE['remember_user']) && parse_str($_COOKIE['remember_pass'])) {

    if(($usr == $remember_user) && ($hash == md5($remember_pass)))
        {
        $_SESSION['username'] = $remember_user;
        }

                $cookie_name = 'siteAuth';
                $cookie_time = time() - 100;
                  setcookie ($cookie_name, 'usr='.$remember_user.'&hash='.$password_hash, time() + $cookie_time);

    }


}
?>

这是我要显示记住的密码的 html 部分

      <input id="password" name="password" placeholder="Password" type="text" autocomplete="on" value="<?php    
  $salt="@g26jQsG&nh*&#8v"; 
  $password = sha1($_COOKIE['remember_pass'].$salt); echo $password; ?>"/>

但仍然在输出中得到这个 f58b28222887e5cd4d10ec75d4bf2617c13a3f4a 我要返回原来的密码 我该怎么做?

【问题讨论】:

  • 你无法解码 sha 256
  • 没有其他方法可以存档吗? @яша
  • 永远不要将密码发送给客户端

标签: php cookies salt


【解决方案1】:
【解决方案2】:

通常当您要进行身份验证时,您或其他任何人都不应该知道客户端的密码!从不意味着永远!

如果您希望进行身份验证,您应该始终遵循以下程序:

客户注册:hash(password+salt) =>插入数据库 客户端身份验证:您检查是否

hash(Input_Password+salt)==(Password in DB)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-05-27
    • 2021-04-15
    • 1970-01-01
    • 1970-01-01
    • 2021-07-23
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多