问题标签 [password-hash]

For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.

0 投票
3 回答
5238 浏览

php - How to get salt from a password and use it to validate user?

I have read tons of questions and tutorials about encrypting a password, and while I've learned a lot, nowhere did I find an answer to this.

I want to use crypt() for hashing a password that I will store on Database. I also know I need to use a salt so it works properly, and I've read that the best way to generate a random salt is by using this or something similar.

If I understood correctly the process is this:

  1. User enters a password
  2. Random create a salt
  3. Hash password and salt
  4. Store result in database

But then how do I recover the salt when user tries to login?

  1. User enters his password
  2. I somehow add his own unique randomly generated salt
  3. Hash both of them together
  4. Compare it to hashed salted password stored in Database.

In a few questions I've found, one of the answers was to store the randomly generated salt on the database. But I thought the whole purpose of salting was to be more secure, if an attacker got access to my DB he would see the 'salt' fields and even if my passwords are encrypted he would gain easy access to accounts.

Other answers said that the 'salt' is prepended to the password when using crypt() so there is no need to store it in a separate field. My question is, how do I get access to it? Is there some function that does this and I'm totally missing?

0 投票
1 回答
1467 浏览

php - 在 Codeigniter 中哈希密码的最佳方法是什么

最近我尝试在 CodeIgniter 中插入密码时散列,如下所示,

但是我遇到了一个错误,说“无法加载请求的类:passwordhash”。请帮我解决这个问题,或者最好的方法是什么。

0 投票
2 回答
1610 浏览

c# - JavaScript 和 C# 兼容的密码哈希

我需要一种在 C# 中散列密码的方法以及在 JavaScript 中散列相同密码并获得相同结果的能力,以实现离线浏览身份验证机制。

我在这里找到了 bCrypt 的 JavaScript 版本:http ://code.google.com/p/javascript-bcrypt/downloads/detail?name=jBCrypt-v2.2.tar.gz ,还有 C# 实现,但我不知道他们是否兼容。

对于我正在开发的网络应用程序,我需要这个,在网络连接可能并不总是可用的情况下,该应用程序可能会被群组中的不同人使用。所有数据都将加载到 Web 应用程序中,但每个用户只能看到他共享的数据。为了实现这一点,即使没有网络连接,我也需要用户进行身份验证。我想我可以通过将所有用户名及其密码哈希(由 ASP.NET MVC / C# 控制器生成)存储在本地存储中来做到这一点。然后,当用户输入他的密码时,我会使用 JavaScript 找到其哈希值,并将其与存储在本地存储中的哈希密码进行比较。

该网络应用程序不处理银行信息或任何类型的此类敏感数据,因此安全要求最低。

0 投票
0 回答
461 浏览

asp.net-mvc - PBKDF2 迭代

我在 ASP.NET 中使用 simplemembershipprovider 进行身份验证。

Microsoft 的内置加密方法(如下)在散列密码时使用 1000 次迭代。每个人都说这还不够,所以我的问题是:我该如何改变呢?我肯定有一种简单的方法可以将一个数字从 1000 更改为 100000 吗?我不想生成自己的安全代码,因为人们说对于没有经验的开发人员来说,安全代码应该远离。我只是接受 1000 是什么吗?

0 投票
0 回答
317 浏览

php - 安全使用 base64_encode

我正在使用 base64 对字符串进行编码。所以目前它可以有“/+=”,但这是一个问题,因为例如我正在上传一个文件,该文件使用 base64_encode 对文件名的一部分进行编码,并且内部可能有一个“/”并破坏了进程。所以我搜索了一下,发现这个函数而不是使用 base64_encode

我对此有两个问题:

  • 编码函数将“+”替换为“-”,但“-”仍为“-”。所以解码函数会将“-”替换为“+”。但也可能是它应该保持“-”。那么这个函数有效吗?对我来说,这听起来像是一个有性格问题的功能。
  • 我正在使用我的私人加密功能来加密密码。此函数使用 base64_encode。那么使用上面的函数会不会有问题呢?如果加密密码当前包含“/”,会出现问题吗?

如果这个功能不好,还有什么替代方法?

很抱歉问这个问题,但我真的不会问这对我来说是否微不足道

0 投票
1 回答
11728 浏览

c# - 如何使用 BCrypt 验证密码

如何检查用户输入的密码是否与其他人已散列并存储到数据库中的密码匹配。通常你会使用这个吗?:

那么,如果您没有包含散列密码的 passwordHash 变量怎么办?

我对 BCrypt 的工作原理不是很了解,所以我认为我遗漏了一些非常简单的东西。

0 投票
1 回答
171 浏览

php - PHP 5.5 password_* functions re-hashing

I have setup my password hashing using PHP password_* functions

1) password_hash($password, PASSWORD_BCRYPT, array("cost" => 11);

2) return password_verify($password, $hashedPassword)? true : false;

Everything work fine.

I found also password_needs_rehash() function, which tak 2 params, $hashedPassword and algorithm, example:

password_needs_rehash($hashedPassword, PASSWORD_BCRYPT);

I understand to use this when it's changed algorithm or cost, something like:

Everything it's clear, I have just a doubt.

I try change the cost, without calling password_needs_rehash() function, and I am able to login.

I try also change on my function which generate hash, I change algorithm from PASSWORD_BCRYPT to PASSWORD_DEFAULT.

I am always able to login.

Can someone explain how does it work?

If we don't re-hash when algorithm change, how PHP password_* handle this?

PS A small question into question... Using php function_* does it raccomanded to use "salt" for password or not?

Thanks!!

0 投票
2 回答
292 浏览

javascript - 用盐加倍哈希密码更安全吗?(稍微复杂一点)

在这种情况下,希望通过 http/s 对用户进行身份验证。

在注册过程中,服务器会生成一个 salt。这个盐被发送给用户。然后他继续通过 js 用盐对他的密码进行哈希处理并将其发送到服务器。在那里,哈希再次用相同的盐加盐,两次散列和加盐的密码被写入带有明文盐的数据库。

如果有人尝试进行身份验证,他会发送他的用户名,获取盐并对密码进行哈希处理。这将发送给再次对其进行哈希处理的服务器,如果保存的哈希值与此相同,则用户已通过身份验证。

我想知道由于最近的心脏出血错误,永远不要暴露真实密码会很好。但是我读过双重哈希会增加碰撞的风险。

我想象的方式是最安全的方式还是我做错了什么?

0 投票
1 回答
941 浏览

security - Rails has_secure_password:它实际上是在数据库中散列密码吗?

使用典型的 Rails 4.1 应用程序has_secure_passwordUser模型password_digest在数据库中有一个列。当我创建一个新用户时,我仍然可以在控制台中访问明文密码:

但是,当我关闭控制台会话并开始新的会话时,我无法再检索明文密码:

我假设明文密码只能在第一种情况下检索,因为它存储在内存中,当我调用u.password => "password"它时,它是从内存中检索值,而不是从数据库中检索值。

我一直认为has_secure_password将(盐+密码)存储为哈希,我认为这意味着理论上不可能(如果我可以使用该术语)反转password_digest并获取原始密码。

我只是确保我假设密码存储为真正的哈希(即无法检索原始密码)是有效的。我已经阅读了Rails has_secure_password API,但它没有澄清我的问题。

0 投票
1 回答
860 浏览

php - 密码哈希和默认盐就够了吗?

我想知道如果

password_hash("custompassgoeshere", PASSWORD_BCRYPT)

足够安全,可以将密码存储到数据库中,或者我是否应该在其中添加更多的 SALT(我在想用户的用户名/电子邮件/出生日期/等等)。

谢谢!