这种密码存储方式安全吗?

发布于 2024-11-27 19:36:45 字数 236 浏览 2 评论 0原文

我只是在想,使用从密码本身创建的盐来创建密码哈希是否可以安全使用。这是 php 中的一个例子:

<?php
$pass = $_GET['pass'];
$salt = hash('whirlpool', $pass);
$pass = md5(hash('whirlpool', $salt.$pass));
echo $pass;
?>

这有意义吗?

问候。

I was just thinking if creating a password hash by using a salt created from the password himself is safe to use. Here an example in php:

<?php
$pass = $_GET['pass'];
$salt = hash('whirlpool', $pass);
$pass = md5(hash('whirlpool', $salt.$pass));
echo $pass;
?>

Does this make sense ?

Regards.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

囚我心虐我身 2024-12-04 19:36:45

盐的目的是使每个人的密码都是唯一的。因此,在这种情况下,当给出相同的原始密码时,仅对他们的密码进行散列并将其添加为盐仍然会使 2 个用户的最终散列密码相等。最好为每个用户提供一个随机盐并将其存储在数据库中的密码旁边。

The point of a salt is to make everyone's password unique. So in this case just hashing their password and adding it as a salt would still make 2 user's final hashed password equal when the same original password is given. Better to give each user a random salt and store that right beside their password in the db.

绿萝 2024-12-04 19:36:45

无需对密码进行哈希、重新哈希和重新哈希。

使用具有良好哈希码算法的盐是一件好事,但您需要强制您的用户发送具有最小大小和字母数字字符的强密码

注释:

  • 使用 sha1 比 md5 更好。
  • 使用好的salt(感谢@John Bartholomew)
  • 强制您的用户创建强密码

It's no necessary to hash and re hash and re re hash the password.

Use a salt with a good hashcode algorithm is a good thing, but you need to force yours users to send a strongly password with a minimum of size and with alphanumeric characters

notes:

  • Using sha1 is better than md5.
  • Using a good salt (thanks @John Bartholomew)
  • Force yours users to create a strongly password
一影成城 2024-12-04 19:36:45

我这样做

<?php

$my_key = "myapp";
$temp_pwd = htmlentities(trim($_POST['password']));
$hashed = sha1($my_key.$temp_pwd);

save $hashed in database on signup
and with every login attemp merge the input password value with your key and make a hash of it and than compare with database password value


?>

I do it like this

<?php

$my_key = "myapp";
$temp_pwd = htmlentities(trim($_POST['password']));
$hashed = sha1($my_key.$temp_pwd);

save $hashed in database on signup
and with every login attemp merge the input password value with your key and make a hash of it and than compare with database password value


?>
深者入戏 2024-12-04 19:36:45

您可以保护您的密码和盐。

  1. 使用 SHA256 或更高版本(2012 年),未来几年它必须更高。

  2. 为每个用户使用不同的盐。

  3. 使用计算出的盐。

  4. 创建一个 16 到 32 字节的 Salt 并将其存储在数据库中,称为“DBSalt”。

  5. 创建任何旧算法来操纵盐,但仅将算法保留在代码中。即使是像 DBSalt + 1 这样简单的东西也是有用的,因为如果有人获取了您的数据库,他们实际上并没有正确的盐,因为正确的盐是计算出来的。

  6. 按如下方式计算您的密码:

    CreateHash(saltAlgorithm(dbSalt),password);

  7. 您可以通过以不同方式操作 DBSalt 的算法列表来增加安全性。每次用户更改密码时,您也会对 DBSalt 使用不同的计算

  8. 您可以通过将这些算法存储在
    Web 服务器位于您的系统外部,因此如果您的数据库和代码都获得
    被黑了,他们仍然没有你的盐。

    1. 您还可以通过设置之前和之后的盐来提高安全性,或者两者都加盐,而数据库本身无法提供此信息。

“您可以通过...提高安全性”的评论层出不穷。请记住,每次增加安全性时,都会增加复杂性、成本等...

如何有效地对数据库中存储为哈希值的密码加盐

You can protect both your password and your salt.

  1. Use SHA256 or higher (2012) and in years to come it must be higher.

  2. Use a different salt for every user.

  3. Use a calculated salt.

  4. Create a 16 to 32 byte Salt and store it in the database, called 'DBSalt'.

  5. Create any old algorithm to manipulate the salt but keep the algorithm only in code. Even something as simple as DBSalt + 1 is useful because if someone gets your database, they don't actually have the correct salt because the correct salt is calculated.

  6. Calculate your password as follows:

    CreateHash(saltAlgorithm(dbSalt), password);

  7. You can add security by having a list of algorithms that manipulate the DBSalt in different ways. Every time a user changes their password you also use a different calculation against the DBSalt

  8. You can add more security by having these algorithms be stored on
    web servers external to your system so if your DB and code both get
    hacked, they still don't have your salt.

    1. You can also increase security by having a before, and after, or both salt and the database alone doesn't provide this information.

There is no end to the "You can increase security by..." comments. Just remember, every time you add security, you add complexity, cost, etc...

How to effectively salt a password stored as a hash in a database

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文