Salted hash password

参考文档

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。

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

时间: 2024-10-12 16:48:43

Salted hash password的相关文章

[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 & salted string which reperstanting the user password. This password is not reverable. And very hard for hacker to guess what is the origial password by usin

Helpers\Password

Helpers\Password The password class uses php 5 password_ functions. To create a hash of a password, call the make method and provide the password to be hashed, once done save the $hash. $hash = Password::make($password); When logging in a user their

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

这篇文章将向你解释如何使用Node.js的Crypto模块对你的密码进行加盐hash.在这里,我们将不会对不懂的密码存储方式进行详细的比较.我们将要做的是知道在Node.js中使用加盐hash在进行密码存储的机制.放心,这是最好的存储密码的方式,在没有出现其他更好的方法之前. 这是什么技术 加盐是这样一直技术:将用户输入的密码和一个随机的字符串(这个字符串就是盐)通过hash结合,通过hash算法生成一个hash值,然后将结果存储在数据库中. 为什么要进行加盐Hash 因为相同密码的hash值是

python通过hashlib库将密码hash后存入数据库

通过Python将密码hash后存入MySQL数据库中,构建一个自己的密码库MySQL版本:5.6python 版本:3.6pycharm:community 2019.2.4 创建相关表 CREATE TABLE society.18wangcode_sha1_hash(id INT(9) AUTO_INCREMENT PRIMARY KEY,pwd VARCHAR(60) NOT NULL, hash_values VARCHAR(40) NOT NULL); Python代码 通过hash

加盐密码哈希:如何正确使用

Salted Password Hashing - Doing it Right If you're a web developer, you've probably had to make a user account system. The most important aspect of a user account system is how user passwords are protected. User account databases are hacked frequentl

如何安全的存储用户密码?(下)代码实现pbkdf2算法加密

这辈子没办法做太多事情,所以每一件都要做到精彩绝伦! People can't do too many things in my life,so everything will be wonderful   乔布斯 本文参考博客: http://wyait.blog.51cto.com/12674066/1918470和 http://wyait.blog.51cto.com/12674066/1918474 参考资料:java API6.0中文版.chm 本文以java为例,进行实际加解密操作

python学习_day26_面向对象之封装

1.私有属性 (1)动态属性 在python中用双下划线开头的方式将属性隐藏起来.类中所有双下划线开头的名称,如__x都会自动变形成:_类名__x的形式.这种自动变形的特点是: a.类中定义的__x只能在内部使用,如self.__x,引用的就是变形的结果.b.这种变形其实正是针对外部的变形,在外部是无法通过__x这个名字访问到的.c.在子类定义的__x不会覆盖在父类定义的__x,因为子类中变形成了:_子类名__x,而父类中变形成了:_父类名__x,即双下滑线开头的属性在继承给子类时,子类是无法覆

III (二十三)OpenLDAP

目录服务: 目录是一类为了浏览和搜索数据而设计的特殊的数据库,目录服务是按照树状形式存储信息,目录包含基于属性的描述性信息,并且支持高级的过滤功能,如microsoft的active directory活动目录就是目录数据库的一种: a directory is like a phone book,and is not like a directory(folder) on your computer 一般目录不支持大多数事务型数据库所支持的高吞吐量和复杂的更新操作,目录进行更新操作是要么全部要

PyQt QString 与 Python str&unicode

昨日,将许久以前做的模拟网页登录脚本用PyQt封装了一下,结果出大问题了, 登录无数次都提示登录失败!!而不用PyQt实现的GUI登录直接脚本登录无数次都提示登录成功!!心中甚是伤痛,于是探究起来,解决这一问题. 问题描述及证据如下: 上图是脚本MD5加密过程及结果 上图是PyQt GUI中获取密码框内容后加密的结果,其实现代码如下: # -*- coding: gbk -*- ''' Version : Python27 Author : Spring God Date : 2013-6-28