代码之家  ›  专栏  ›  技术社区  ›  Erlisar Vasquez

password\u verify()如何比较密码和散列密码?

php
  •  -3
  • Erlisar Vasquez  · 技术社区  · 6 年前

    有人知道 password_verify() php.net :

    bool password_verify ( string $password , string `$hash` )
    

    $password

    $hash 不如把它和 $密码

    2 回复  |  直到 6 年前
        1
  •  4
  •   Quentin    6 年前

    因为散列函数的关键是 无法反转 password_verify 不能使用选项2。

    剩下选项1。

    the source code

    zend_string *ret = php_crypt(ZSTR_VAL(password), (int)ZSTR_LEN(password), ZSTR_VAL(hash), (int)ZSTR_LEN(hash), 1);
    

    它将密码加密,然后

    /* We're using this method instead of == in order to provide
    * resistance towards timing attacks. This is a constant time
    * equality check that will always check every byte of both
    * values. */
    for (i = 0; i < ZSTR_LEN(hash); i++) {
        status |= (ZSTR_VAL(ret)[i] ^ ZSTR_VAL(hash)[i]);
    }
    

    ret hash )

        2
  •  3
  •   Philipp    6 年前

    没有“去灰化”这回事。散列是单向函数。

    password_verify password_hash 然后使用给定的参数再次执行完全相同的哈希运算。

    因此,使用 密码\u验证 $hash == password_hash('...') ,作为 可以使用一个散列算法,每次创建一个新的随机盐值。这么叫 密码\u哈希 在同一台机器上多次使用同一个输入,将永远不会返回相同的值。