我应该在将密码发送到服务器端之前对其进行哈希处理吗? [英] Should I hash the password before sending it to the server side?

查看:26
本文介绍了我应该在将密码发送到服务器端之前对其进行哈希处理吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我注意到大多数站点通过 HTTPS 将密码作为纯文本发送到服务器.如果我将密码的哈希值发送到服务器而不是它,有什么好处吗?会更安全吗?

I noticed that most sites send the passwords as plain text over HTTPS to the server. Is there any advantage if instead of that I sent the hash of the password to the server? Would it be more secure?

推荐答案

这是一个老问题,但我觉得有必要就这个重要问题提供我的意见.这里的错误信息太多了

This is an old question, but I felt the need to provide my opinion on this important matter. There is so much misinformation here

OP 从未提及通过 HTTP 以明文方式发送密码 - 仅使用 HTTPS,但出于某种原因,许多人似乎正在回答通过 HTTP 发送密码的问题.那就是:

The OP never mentioned sending the password in clear over HTTP - only HTTPS, yet many seem to be responding to the question of sending a password over HTTP for some reason. That said:

我相信密码永远不应该以纯文本形式保留(更不用说传输)了.这意味着不会保存在磁盘上,甚至不会保存在内存中.

I believe passwords should never be retained (let alone transmitted) in plain text. That means not kept on disk, or even in memory.

在这里做出回应的人似乎认为 HTTPS 是灵丹妙药,但事实并非如此.然而,它确实有很大帮助,并且应该在任何经过​​身份验证的会话中使用.

People responding here seem to think HTTPS is a silver bullet, which it is not. It certainly helps greatly however, and should be used in any authenticated session.

确实不需要知道原始密码是什么.所需要的只是一种基于原始文本生成(并可靠地重新生成)身份验证密钥"的可靠方法由用户选择.在理想的世界中,此文本应通过使用不可逆盐对其进行散列来立即生成密钥".此盐对于正在生成的用户凭据应该是唯一的.这个密钥"将是您的系统用作密码的东西.这样,如果您的系统将来遭到入侵,这些凭据只会对您自己的组织有用,而在用户懒惰并使用相同密码的其他地方则无用.

There is really no need to know what an original password is. All that is required is a reliable way to generate (and reliably re-generate) an authentication "key" based on the original text chosen by the user. In an ideal world this text should immediately generate a "key" by hashing it using irreversible salt. This salt should be unique to the user credential being generated. This "key" will be what your systems use as a password. This way if your systems ever get compromised in the future, these credentials will only ever be useful against your own organisation, and nowhere else where the user has been lazy and used the same password.

所以我们有一把钥匙.现在我们需要清除客户端设备上的任何密码痕迹.

So we have a key. Now we need to clean up any trace of the password on the clients device.

接下来,我们需要获取您系统的密钥.您永远不应该以明文形式"传输密钥或密码.甚至不是通过 HTTPS.HTTPS 并非不可渗透.事实上,许多组织可以成为受信任的中间人——不是从攻击的角度来看,而是对流量进行检查以实施他们自己的安全策略.这削弱了 HTTPS,而且这不是它发生的唯一方式(例如重定向到 HTTP MITM 攻击).永远不要假设它是安全的.

Next we need to get that key to your systems. You should never transmit a key or password "in the clear". Not even over HTTPS. HTTPS is not impenetrable. In fact, many organisations can become a trusted MITM - not from an attack perspective, but to perform inspections on the traffic to implement their own security policies. This weakens HTTPS, and it is not the only way it happens (such as redirects to HTTP MITM attacks for example). Never assume it is secure.

为了解决这个问题,我们用一次性随机数散列密钥.对于每次向系统提交密钥时,此随机数都是唯一的——即使是在同一会话期间,如果您需要多次发送相同的凭证,也是如此.一旦它到达您自己的系统,您就可以反转此随机数以恢复身份验证密钥,并对请求进行身份验证.

To get around this, we hash the key with a once off nonce. This nonce is unique for every submission of a key to your systems - even for the same credential during the same session if you need to send it multiple times. You can reverse this nonce once it arrives in your own systems to recover the authentication key, and authenticate the request.

在这一点上,我会在它永久存储在您自己的系统中之前最后一次不可逆转地散列它.这样,您可以出于 SSO 等目的与合作伙伴组织共享凭证的盐,同时能够证明您自己的组织不能冒充用户.这种方法的最佳部分是您绝不会在未经用户授权的情况下共享用户生成的任何内容.

At this point I would irreversibly hash it one last time before it is permanently stored in your own systems. That way you can share the credential's salt with partner organisations for the purposes of SSO and the like, whilst being able to prove your own organisation cannot impersonate the user. The best part of this approach is you are never sharing anything generated by the user without their authorisation.

做更多的研究,因为它比我透露的还要多,但如果你想为你的用户提供真正的安全,我认为这个方法是目前最完整的回应.

Do more research, as there is more to it than even I have divulged, but if you want to provide true security to your users, I think this method is currently the most complete response here.

TL;博士:

使用 HTTPS.安全地散列密码,不可逆转,每个密码都有一个唯一的盐.在客户端上执行此操作 - 不要传输他们的实际密码.将用户原始密码传输到您的服务器永远不会OK"或Fine".清除原始密码的任何痕迹.使用 nonce 而不管 HTTP/HTTPS.它在许多层面上都更加安全.(对 OP 的回答).

Use HTTPS. Securely hash passwords, irreversibly, with a unique salt per password. Do this on the client - do not transmit their actual password. Transmitting the users original password to your servers is never "OK" or "Fine". Clean up any trace of the original password. Use a nonce regardless of HTTP/HTTPS. It is much more secure on many levels. (Answer to OP).

这篇关于我应该在将密码发送到服务器端之前对其进行哈希处理吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆