- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
首先,我对一般编码相当陌生,因此散列的概念有点令人困惑。本质上,我试图对密码进行哈希处理,以便将其存储在数据库中,因此我没有纯文本形式的密码(我被告知这是最好的方法,尽管我不认为会是这样)如果密码没有经过哈希处理,那就是一个很大的问题,因为这仅在一小群人中使用,我可以通知他们不要使用他们关心的密码,但仍然建议我这样做)。
我查阅了一些指南,并且可以使用一些帮助来理解这一点。我将包括对密码进行哈希处理的方式以及如何将它们从数据库中提取出来,以帮助理解这个问题。如果这是一个愚蠢的问题,请提前道歉。请注意,我不太明白这一点,这就是我问这个问题的原因。
注意:诸如 $login_username 和 $login_password 之类的包含变量已被正确提取,我只是不想包含它们,因为它会使帖子变得更加困惑。
注册用户(已尝试password_default和password_bcrypt,但我没有看到区别):
require_once 'database.php';
$hash_employee_password = password_hash($employee_password, PASSWORD_DEFAULT);
$query = "INSERT INTO employee
(employee_id, employee_first_name, employee_last_name,
employee_username, employee_email, employee_password)
VALUES
(:employee_id, :employee_first_name, :employee_last_name,
:employee_username, :employee_email, :employee_password);";
//VALUES (".$employee_id.", '" . $employee_first_name."', '" . $employee_last_name . "', '".$employee_username."', '".$employee_email."', '" . "$employee_password');";
$statement = $db->prepare($query);
$statement->bindValue(':employee_id', $employee_id);
$statement->bindValue(':employee_first_name', $employee_first_name);
$statement->bindValue(':employee_last_name', $employee_last_name);
$statement->bindValue(':employee_username', $employee_username);
$statement->bindValue(':employee_password', $hash_employee_password);
$statement->bindValue(':employee_email', $employee_email);
$statement->execute();
$statement->closeCursor();
//echo $query;
$message = 'You have been successfully registered. Contact your manager in order to request account confirmation.';
include ('success.php');
记录登录:
require_once 'database.php';
include 'register_user.php';
$pwordQuery = "SELECT employee_password from employee where employee_username = :login_username";
$pwstatement = $db->prepare($pwordQuery);
$pwstatement->bindValue(':login_username', $login_username);
$pwstatement->execute();
$result = $pwstatement->fetch();
$pwstatement->closeCursor();
echo $result[0];
if(password_verify($login_password, $result[0]))
{
echo ' TRUE';
}
else
{
echo ' FALSE ';
}
问题是:我输入了正确的用户名和密码,但得到的结果是“FALSE”回显。如果您有任何想法,请告诉我。忽略这样一个事实:我有大量工作要做,例如将查询放入函数中并以这种方式调用它们......这些都保存到以后。
最佳答案
"password column's length is what? if it's anything less than 60, mysql failed on you silently. 9 times out of 10, that's what the problem is. If so, then you'll need to start all over again by clearing your db and create a new hash. – Fred -ii- 13 mins ago"
我一直以来都是对的:
@Fred Well it looks like having the column length being 45 was a bad idea and that was my only problem. Thanks for the help, not entirely sure how this site works so I don't know how to give you rep or anything."
根据 password_hash()
函数的手册:
http://php.net/manual/en/function.password-hash.php
PASSWORD_DEFAULT - Use the bcrypt algorithm (default as of PHP 5.5.0). Note that this constant is designed to change over time as new and stronger algorithms are added to PHP. For that reason, the length of the result from using this identifier can change over time. Therefore, it is recommended to store the result in a database column that can expand beyond 60 characters (255 characters would be a good choice).
关于PHP 和 SQL 哈希帮助 : What am I doing wrong?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41063420/
这个问题在这里已经有了答案: java.lang.IllegalArgumentException: The servlets named [X] and [Y] are both mapped t
我无法让我的 WebRTC 代码正常工作。我相信我所做的一切都是正确的,但它仍然无法正常工作。为什么 ontrack 这么早就被调用有些奇怪,也许它应该是那样的。 该网站使用 javascript 代
使用 Mac OSX 优胜美地 (10.10.4): rails -v => Rails 4.2.3 ruby -v => ruby 2.2.2p95 遵循这些说明的组合: https://www
您好,我正在尝试使用(缓存的)已编译的 lambda 表达式来访问属性,与使用 PropertyInfo.GetValue()/SetValue() 方法调用相比,我确实得到了更好(即更快)的结果。然
我编写此代码是为了获取学生的字母成绩并计算他们的 GPA。当我运行该程序时,我可以正确获取学生的姓名和科目,但无法显示成绩或 GPA。 示例输入: Sally 1 A N 示例输出: Enter St
我一直在编写这段代码,根据这本书应该可以做到这一点: Write a script that creates and calls a stored procedure named test. This
我真的很难创建一个具有以下基本格式的有效多维 JavaScript 数组: var countries = [ { "country": "UK", "properties": {
我有一个小型 Python OOP 程序,其中 2 个类 Flan 和 Outil 继承自父类(super class) Part。 我的问题是,当我调用 Flan 时一切正常,但是当我调用 Outi
我目前正在尝试使用通用监听器来编写事件系统。 所有监听器都应添加到单个 EventSource 对象,该对象将为特定事件调用其 receiveEvent() 方法。 事件源: public class
我正在通过我的 PHP 应用程序发送电子邮件。但是,它们被 Gmail 标记为垃圾邮件。这是我发送电子邮件的方式(PHP): $headers = "From: test@bookmytakeout.
我已经正式走到了穷途末路的地步。我找不到我做错了什么。我完成的这个程序几乎与我几天前编写的另一个程序一模一样,但我在编译时遇到了问题。我不知道为什么输出线上出现错误。请帮忙: 这是正在运行的文件: p
---编辑:我不允许使用任何包或预置方法。不用担心,我不想让你做我的“作业”,我只需要一点提示!---我发现these interesting Algorithms 。我想使用按位添加方法。我的问题是
我制作了一个小程序,尝试使用 conn.getOutputStream(); 检索 URLConnection 对象输出流。当我尝试执行此操作时,我的小程序抛出异常 java.net.UnknownS
每当我尝试在 SVN 中合并时,我都会遇到成堆的树冲突。好吧,就此示例脚本而言,只有一个,但仍然如此。 #!/bin/bash svnadmin create repo svn checkout fi
我开始为 Scala 中的 X500PrincipalBuilder 类编写单元测试。这是我的测试代码: import org.junit.runner.RunWith import org.scal
我正在用 python 编写我的第一个程序,它必须模拟粒子(两种气体)的混合。我不知道我这个功能做错了什么。我不希望颗粒离开某些区域,即容器的壁。我使用 VPython。 def poruszanie
我正在尝试求解三角方程组,但我认为 Python 没有生成正确的解。我试图解决的方程: 1 − 2cosθ1 + 2cosθ2 − 2cosθ3 = −0.8 1 − 2cos5θ1 + 2cos5θ
这个问题已经有答案了: TypeError: worker() takes 0 positional arguments but 1 was given [duplicate] (11 个回答) 已关
大家好,我正在努力解决这个问题 编写一个 C 程序,计算弹丸在撞击地面之前行进的距离(即射程)、弹丸撞击地面所需的时间以及弹丸飞行中的最大高度(给定角度)它被射向空中,以及发射时的初始速度(速度)。我
我编写了代码来计算 QuickSort 中完成的比较次数。 每当对长度为 m 的数组执行快速排序时,该算法都会将比较次数增加 m-1(因为主元将与除自身以外的所有内容进行比较)。 枢轴的选择始终是数组
我是一名优秀的程序员,十分优秀!