栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

为什么werkzeugs`generate_password_hash`的输出不是恒定的?

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

为什么werkzeugs`generate_password_hash`的输出不是恒定的?

由于每次调用该函数时都会随机生成盐,因此生成的密码哈希也不同。返回的哈希值包含生成的盐,因此仍可以正确验证密码。

演示:

>>> from werkzeug.security import generate_password_hash>>> generate_password_hash('foobar')'pbkdf2:sha1:1000$tYqN0VeL$2ee2568465fa30c1e6680196f8bb9eb0d2ca072d'>>> generate_password_hash('foobar')'pbkdf2:sha1:1000$XHj5nlLU$bb9a81bc54e7d6e11d9ab212cd143e768ea6225d'

这两个字符串不同。但包含足够的信息来验证密码,因为生成的盐包含在每个密码中:

# pbkdf2:sha1:1000$tYqN0VeL$2ee2568465fa30c1e6680196f8bb9eb0d2ca072d  ^^^^^^^^^^^^^^^^   salt   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^      algo info    ^^^^^^^^        actual hash of the password  (PBKDF2 applied SHA1 1000 times)

Because the random salt is

tYqN0VeL
for one and
XHj5nlLU
, the resulting hash is also different.

The

foobar
password can still be verified against either hash:

>>> from werkzeug.security import check_password_hash>>> check_password_hash('pbkdf2:sha1:1000$tYqN0VeL$2ee2568465fa30c1e6680196f8bb9eb0d2ca072d', 'foobar')True>>> check_password_hash('pbkdf2:sha1:1000$XHj5nlLU$bb9a81bc54e7d6e11d9ab212cd143e768ea6225d', 'foobar')True


转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/387095.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号