【问题标题】:PHP Password HashingPHP密码散列
【发布时间】:2012-05-30 16:15:38
【问题描述】:

目前我有这行代码

<?php
    $pass = "12312312";
    echo md5(crypt($pass))
?>

我知道 crypt 可以随机生成盐,但我不知道如何在用户输入上进行比较。

我的登录表需要哪些字段? 还有,我将向我的表中插入哪些数据?

谢谢!

【问题讨论】:

  • md5 坏了,所以你应该使用别的东西。试试 bcrypt。
  • 谢谢!!但我需要哪些字段?嗯,我可以在 1 个字段中同时插入带盐的密码吗?还是我需要一个盐场?
  • 您需要将盐存储在它自己的字段中。
  • 这是我的表结构 tblogin user_id 用户名密码 salt 这个对吗?

标签: php passwords password-protection


【解决方案1】:

您可以将密码存储在下表中

$pass = "12312312";

// store this in table with separate column
$salt = md5("any variable"); // may be email or username

// generate password
$password = sha1($salt.$pass);

// now store salt and password in table

你可以像这样检查密码

$pass = "User input";

// get the user from database based on user id or username
// and test the password stored in db with

if($passwordFromTable == sha1($saltFromTable.$pass))
{
    // correct
}

【讨论】:

    猜你喜欢
    • 2015-08-13
    • 2011-04-06
    • 2015-10-27
    • 2018-07-29
    • 1970-01-01
    • 2017-06-26
    • 2014-09-09
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多