PHP 中的 MySQL 密码比较
下午好。基本上我有一个带有登录表单的页面,要求用户输入用户名和密码。然后我将这些用户名和密码的哈希版本与 MySQL 中的密码数据库进行匹配。
现在,由于我不知道黑客/漏洞利用者有什么能力,我只想永远不要从数据库中检索正确密码的散列版本并在服务器上进行比较。我已经搜索了谷歌和 MySQL 教程网站,但我似乎无法得到明确的答案(我可能在这里淹没在浅水里)。基本上这就是我想要做的:
- 用户输入用户名+密码。
- 我通过存储过程将此信息转发到 MySQL。
- 如果找到匹配项,存储过程将返回 TRUE/FALSE(1 或 0 并不重要)。
非常感谢您抽出时间。
Afternoon SO. Basically I have a page with a login form where the user is asked to input their username and password. Then i match these username and a hashed version of the password with the Passwords database in MySQL.
Now, seeing as I have no idea what hackers/expoilters are capable of i would just like to never retrieve the hashed version of the right password from the database and compare it on the server. I have scoured google and the MySQL tutorial websites but I cant seem to get a clear answer (i might be drowning in shallow water here). Basically this is what i want to do:
- User inputs username + password.
- I forward this information to MySQL through a stored procedure.
- Stored procedure returns TRUE/FALSE (1 or 0 doesnt matter) if a match is found.
Thankyou very much for your time.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我不太确定你在做什么,但如果我正确理解了这个问题,你想做这样的事情:
然后将密码与 PHP 进行比较,你担心这可能会成为一个安全问题。
我认为这从安全角度来看没有任何区别。检查密码是否正确的常用方法是:
如果 count == 1,则用户给出了正确的密码。您可以看到,如果密码不匹配,MySQL 在任何时候都不会给出实际密码。即使确实如此,黑客也几乎不可能访问该信息。如果他们可以,他们已经劫持了您的服务器,这是您遇到的最小问题。
I'm not quite sure what you're after, but if I understood the question correctly, you want to do something like this:
and then compare the passwords with PHP, and you're concerned that this might become a security issue.
I don't think it makes any difference in the security standpoint. The usual way of checking if the password is correct is:
If count == 1, the user gave the correct password. You can see that MySQL doesn't give the actual password at any point if the passwords don't match. Even if it did, it's nearly impossible for a hacker to get access to that information. If they can, they have already hijacked your server and this is the least of your problems.
将凭据发送到数据库时只需使用 mysql_real_escape_string 即可。这将防止 SQL 注入。
http://www.php.net/manual/en /function.mysql-real-escape-string.php
Just use
mysql_real_escape_string
when sending the credentials to your database. This will prevent SQL injection.http://www.php.net/manual/en/function.mysql-real-escape-string.php