尝试对我的密码进行哈希处理但没有成功
我对 php 安全性相当陌生,对于我的网站,我是注册和登录,我想添加 md5 他们的密码,但我找不到任何地方有关于需要添加到哪些内容的明确指南注册,以及需要添加到登录文件和/或数据库中的内容,正如我所说,我在网络安全方面对 php 相当陌生,所以我需要一些帮助,这是我所拥有的部分在我的注册表单上:
$error = $user = $pass = "";
if (isset($_SESSION['user'])) destroySession();
if (isset($_POST['user']))
{
$user = sanitizeString($_POST['user']);
$pass = sanitizeString($_POST['pass']);
if ($user == "" || $pass == "")
{
$error = "Not all fields were entered<br /><br />";
}
else
{
$query = "SELECT * FROM members WHERE user='$user'";
if (mysql_num_rows(queryMysql($query)))
{
$error = "Username already taken<br /><br />";
}
else
{
$query = "INSERT INTO members VALUES('$user', '$pass')";
queryMysql($query);
die("<h4>Account created</h4>Please Log in.");
}
}
}
我只需要一个示例或一个很好的指南来说明我需要做什么才能使其正常工作。
I am fairly new to php security, and for my site, I was a sign up and login, and I want to add md5 their passwords, but I can't find anywhere which has a clear guide on what needs to be added to the sign up, and what needs to be added to the login files, and/or the database, as I say I am fairly new to php in terms of web security, so I am in need of some help, here's part of what I have on my sign up form:
$error = $user = $pass = "";
if (isset($_SESSION['user'])) destroySession();
if (isset($_POST['user']))
{
$user = sanitizeString($_POST['user']);
$pass = sanitizeString($_POST['pass']);
if ($user == "" || $pass == "")
{
$error = "Not all fields were entered<br /><br />";
}
else
{
$query = "SELECT * FROM members WHERE user='$user'";
if (mysql_num_rows(queryMysql($query)))
{
$error = "Username already taken<br /><br />";
}
else
{
$query = "INSERT INTO members VALUES('$user', '$pass')";
queryMysql($query);
die("<h4>Account created</h4>Please Log in.");
}
}
}
I just need an example or a good guide of what I need to do to get it working correctly.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我认为您正在寻找加盐然后散列您的密码。只需将您选择的字符串添加到密码的前面(如果您愿意,也可以添加到密码的末尾),然后使用 MD5 对其进行哈希处理。
例如,
这将使用加盐 MD5 加密将密码存储在数据库中,并且无法使用使用未加盐 MD5 加密的常见密码查找表来反转该密码。
要检查密码是否有效,您可以执行类似的操作:
I think you're looking to salt and then hash your passwords. Simply add a string of your choosing to the front (and if you wish, to the end) of your password before hashing it using MD5.
e.g.
This will store the password in the database using salted MD5 encryption that cannot be reversed using a lookup table of common passwords using unsalted MD5 encryption.
To check if a password is valid, you do something similar:
例如,您可以在插入之前进行 md5($pass) ,当用户登录时,您可以再次进行 md5 并检查值是否相同。无法去除 md5,因此您通常会根据 md5 DB 值检查 md5 输入。
You can for example md5($pass) before you insert and when the user logs in, you md5 again and check that the values are the same. There is no way to de-md5, so you will usually check the md5 input against the md5 DB value.