参考文档

http://www.cnblogs.com/richardlee/articles/2511321.html

https://en.wikipedia.org/wiki/Salt_%28cryptography%29

https://www.91ri.org/7593.html

密码存储为什么不能是明文?

当账户密码是明文存储的话, 万一本网站给黑客攻破获取了数据, 则用户的账户被泄露。(术语叫 拖库)

当黑客知道了你的账户后, 其可以使用此账户,到其他网站尝试访问, 例如有厉害关系的网站, 银行等。 (术语叫 撞库)

一般来说, 普通用户为了减少密码记忆负担, 则容易在所有网站, 设置相同密码。

为了减少用户注册登陆流程,新的网站一般使用公共账户认证服务, 例如(qq 微信 等), 这样也可以减少拖库撞库危险。

密码应该以hash形式存储?

不能以明文形式存储, 自然以密文方式存储。

如果使用 对称加密方式, 则加密和解密的秘钥, 必须存储在网站上, 一旦密钥和算法泄露 并且 库被拖走, 密码就可以被直接计算出来,则密码的安全性仍然不能保证。

密码以hash方式存储, 则保证密码不能被反向计算出来, 就算网站的维护人员, 也不能查看到原始密码是多少。 最多其能看到一串 hash值。

黑客就算拿到hash值, 由于hash值不能被反向还原, 例如 MD5 SHA, 也只能悻悻然。

这样保证用户密码的安全性。

密码计算hash为什么要添加salt?

试想,如果对于每个密码, 都直接采用某种hash算法, 计算得到hash值。

对于一些简单密码, 其hash值是固定的, 则可以构造所有 最易使用的简单密码 的 hash值 成为一个表,

当黑客拖库拿到 密码的 hash值后,  其使用构造表中的 hash值比较, 如果你相等, 则得到 密码的原始值。

所以每年都有最弱密码排名, 提醒广大互联网用户, 不要使用简单密码。

http://tech.163.com/12/1029/04/8EV6LS9U000915BF.html

对于每一个密码都生成一个随机数(salt), 计算hash值的时候,将 salt 和 密码拼接后作为入参, 得到的hash值, 可以解决一张hash表, 尝试破解所有密码的问题。

但是对于单个密码, 其salt也被泄露, 如果即时构造一个 带salt的 hash表, 同样也可以破解密码。

如何加salt?

http://www.cnblogs.com/richardlee/articles/2511321.html

How long should the salt be?

The salt should be at least as long as the hash function. For example, if your hash function is 256 bits, then you should have a salt of at least 256 bits. I find that the easiest way to generate enough salt is to generate a random string of hex characters that is the same length as the hash function output (64 hex characters for 256 bits). First and foremost, your salt should be long enough so that no two users' passwords will ever be hashed using the same salt.

How do I generate the salt?

Use a Cryptographically Secure Pseudo-Random Number Generator (CSPRNG). Do NOT use your language's math library's rand() function. There will be a proper CSPRNG for you to use. In PHP, it's mcrypt_create_iv() and in .NET it's System.Security.Cryptography.RNGCryptoServiceProvider. The imporant thing is that the salt is uniquefor each user. Using a high quality CSPRNG to generate a long salt will practically guarantee uniqueness without needing to manually check if the salt has been used before.

如何选择hash算法?

What hash algorithm should I use?

DO use:

DO NOT use:

    • MD5
    • SHA0 or SHA1
    • crypt unless it uses SHA256 or SHA512
    • Any algorithm that you made yourself or hasn't gone through an intensive peer review process like the SHA3 competition

是否加了盐, 密码就安全了?

不是的, 添加了salt,是提高了破解的难度。  但是如果密码本身是不安全的, 例如非常简单的规则 纯数字 , 则很容易被破解。 不管是否添加salt。

所以一些网站要求, 密码 必须包含 字母 数字, 外还必须添加一种特殊符号。

Salted hash password的更多相关文章

  1. [Web Security] Create a hash salt password which can stored in DB

    We cannot directly store user password in the database. What need to do is creating a hashed & s ...

  2. 数据库里账号的密码,需要怎样安全的存放?—— 密码哈希(Password Hash)

    最早在大学的时候,只知道用 MD5 来存用户的账号的密码,但其实这非常不安全,而所用到的哈希函数,深入挖掘,也发现并不简单-- 一.普通的 Hash 函数 哈希(散列)函数是什么就不赘述了. 1.不推 ...

  3. Spring Security(三十三):10.3 Password Encoding

    Spring Security’s PasswordEncoder interface is used to support the use of passwords which are encode ...

  4. 对抗密码破解 —— Web 前端慢 Hash

    (更新:https://www.cnblogs.com/index-html/p/frontend_kdf.html ) 0x00 前言 天下武功,唯快不破.但在密码学中则不同.算法越快,越容易破. ...

  5. Hash 函数及其重要性

    不时会爆出网站的服务器和数据库被盗取,考虑到这点,就要确保用户一些敏感数据(例如密码)的安全性.今天,我们要学的是 hash 背后的基础知识,以及如何用它来保护你的 web 应用的密码. 申明 密码学 ...

  6. 理解php Hash函数,增强密码安全

    1.声明 密码学是一个复杂的话题,我也不是这方面的专家.许多高校和研究机构在这方面都有长期的研究.在这篇文章里,我希望尽量使用简单易懂的方式向你展示一种安全存储Web程序密码的方法. 2.“Hash” ...

  7. Helpers\Password

    Helpers\Password The password class uses php 5 password_ functions. To create a hash of a password, ...

  8. 使用nodeJS的 crypto模块来为你的密码hash加盐

    这篇文章将向你解释如何使用Node.js的Crypto模块对你的密码进行加盐hash.在这里,我们将不会对不懂的密码存储方式进行详细的比较.我们将要做的是知道在Node.js中使用加盐hash在进行密 ...

  9. 对抗明文口令泄露 —— Web 前端慢 Hash

    (更新:https://www.cnblogs.com/index-html/p/frontend_kdf.html ) 0x00 前言 天下武功,唯快不破.但在密码学中则不同.算法越快,越容易破. ...

随机推荐

  1. sed 格式化输出df -h

    df -h|sed '1d;/ /!N;s/\n//;s/ \+/ /;' 1d——————删除第一行 / /!N——————没有空格的行执行N 例子中没有空格的行 /dev/mapper/vg_ds ...

  2. JS:操作样式表1:行内样式

    //访问元素样式1, stye属性只对行内样式有用 var box = document.getElementById("box"); // alert(box.style.col ...

  3. Flex 页面空白或Error #2032

    日前用flex.arcgis做了一个地图显示的页面,本机调试没题目,公布后放到用户办事器上(win2003,ie6)ie6显示页面空白,换搜狗浏览器显示Error #2032,只显示进度条,客户端用i ...

  4. 广播变量、累加器、collect

    广播变量.累加器.collect spark集群由两类集群构成:一个驱动程序,多个执行程序. 1.广播变量 broadcast 广播变量为只读变量,它由运行sparkContext的驱动程序创建后发送 ...

  5. Big Chocolate

    Big Chocolate 题目链接:http://acm.hust.edu.cn/vjudge/problem/visitOriginUrl.action?id=19127 Big Chocolat ...

  6. [转]关于event的两个常被忽略的api:isDefaultPrevented()和preventDefault()

    今天在robert penner(as3 singal的作者)的一篇blog文中顺藤摸瓜到了darron schall的另外一篇blog文(Creating Default, Cancelable E ...

  7. 【腾讯云】腾讯云服务器搭建ftp服务器

    一.硬件描述 1.1 云服务器:腾讯云 云主机 操作系统:Ubuntu Server 14.04.1 LTS 32位 CPU:1核 内存:1GB 系统盘:20GB(本地磁盘) 数据盘:0GB 公网带宽 ...

  8. 【LeetCode】16. 4Sum

    题目:Given an array S of n integers, are there elements a, b, c, and d in S such that a + b + c + d = ...

  9. Daily Scrum 11.5

    今天成员全部到齐,对今天的工作进行了总结,并对明天的工作作了安排.由于先前分配的任务都已基本完成,要完成程序的三级优化是较为艰巨的任务.所以我们讨论决定,除PM外其他成员都投入到程序的优化和改进中去. ...

  10. js实现时钟

    <!DOCTYPE html> <html> <head> <title>Js版带表盘的时钟</title> <meta charse ...