
password_hash第二个参数PASSWORD_BCRYPT和PASSWORD_DEFAULT分明就是同一个参数……
还有。 bcrypt 计算出来的为啥是$2y 开头的? python 中 bcrypt 计算出来的都是$2a 开头的啊,为啥? php 生成的密码到 python 里还能用么?
1 haiyang416 2015 年 9 月 4 日 直接用估计是不行的了, PHP 的 Base64 字符集都和标准的不同。 |
2 haiyang416 2015 年 9 月 4 日 @haiyang416 先收回这句话,搜了一圈没找到出处了。 |
3 caixiexin 2015 年 9 月 4 日 模块化算法 BCrypt 的格式由 $2$ , $2a$ or $2y$ 标识的哈希算法和格式。 两个数字参数表示的成本值, 后面跟着 $ 一个字符长的 53 base-64-encoded ( 它们使用字母值 . , / , 0 9 , A Z , a z 不同的 标准 Base 64 Encoding 字母组成的) : 仅 22 字符的盐( 有效地 128 ) 132 解码后的位位 31 加密的字符输出( 有效地只 184 ) 186 解码后的位位 因此总长度是 59 或者 60 字节分别。 ----------------------- 以前查 bcrypt 资料看到的,可能 python 和 php 实现 bcrypt 哈希算法略有不同。具体你可以找找 bcrypt 的详细说明:) |
4 haiyang416 2015 年 9 月 4 日 |
5 breeswish 2015 年 9 月 4 日 固定 cost 试试 |
6 cevincheung OP @breeswish 跟 cost 没关系, cost 是第二部分的值比如$2y$cost$、$2y$07$ |
7 cevincheung OP @caixiexin 所以这个算法不是统一的么?是不是可以理解成 php 的 bcrypt 未“完全”实现? |
8 skydiver 2015 年 9 月 4 日 CRYPT_BLOWFISH - Blowfish hashing with a salt as follows: "$2a$", "$2x$" or "$2y$", a two digit cost parameter, "$", and 22 characters from the alphabet "./0-9A-Za-z". Using characters outside of this range in the salt will cause crypt () to return a zero-length string. The two digit cost parameter is the base-2 logarithm of the iteration count for the underlying Blowfish-based hashing algorithmeter and must be in range 04-31, values outside this range will cause crypt () to fail. Versions of PHP before 5.3.7 only support "$2a$" as the salt prefix: PHP 5.3.7 introduced the new prefixes to fix a security weakness in the Blowfish implementation. Please refer to this document for full details of the security fix, but to summarise, developers targeting only PHP 5.3.7 and later should use "$2y$" in preference to "$2a$". 这里有说明 http://php.net/manual/en/function.crypt.php |
9 cevincheung OP @skydiver 所以潜台词是$2a 可能存在不安全的潜在风险? |
10 breeswish 2015 年 9 月 4 日 @cevincheung 抱歉没仔细看 :-) 确实是算法不一样,具体解释在这里 http://security.stackexchange.com/questions/20541/insecure-versions-of-crypt-hashes/20543#20543 Python 下可以用 passlib.hash.bcrypt 生成 2y 的 bcrypt : https://pythonhosted.org/passlib/lib/passlib.hash.bcrypt.html |
11 skydiver 2015 年 9 月 4 日 @cevincheung 看着是这个意思 |
12 laoyuan 2015 年 9 月 4 日 毕竟宇宙第一 |
13 raincious 2015 年 9 月 5 日 关于 2a 和 2y 前缀的问题,其实这个跟你用的 Salt 有关系,如果的 Salt 是 2a 开头的,那么 crypt 就会用 2a 算法运算结果然后得到一个 2a 开头的序列, 2y 也同理。 password_hash 默认的 Salt 给的就是 2y 前缀,所以自然结果也就是 2y 开头的。 |
14 cevincheung OP @raincious 这样的 var_dump (PASSWORD_DEFAULT )结果是 integer 1 var_dump (PASSWORD_BCRYPT )结果是 integer 1 那给这两个配置有毛用? |
15 raincious 2015 年 9 月 5 日 @raincious 你可以理解成 PASSWORD_DEFAULT 就是选择一个默认值,而默认值是 PASSWORD_BCRYPT 啊。( *手动笑哭* 要是有多个常数的话,可能就不会有这种感觉了, 比如选项是: PASSWORD_ASMILEPT PASSWORD_BCRYPT PASSWORD_CLAUGHPT PASSWORD_DRAGEPT PASSWORD_ENVYPT PASSWORD_FROWNPT PASSWORD_GIGGLEPT 默认值 PASSWORD_DEFAULT 是 PASSWORD_BCRYPT |
16 chaegumi 2016 年 8 月 11 日 最搞笑的是现在要接入 jasig cas ,别人是 2a php 是 2y ,接入 jasig cas 的密码验证还得自己写个 2y 的来匹配 |
17 verytoex 2017 年 12 月 21 日 我测试过,用 spring.security 来校验 PHP 创建的 hash,只要把 2y 替换成 2a 就能校验通过了。 PHP 兼容 2a 和 2y,两个都支持。 |