Maximum length of generated hash when using password_hash?

前端 未结 2 611
遥遥无期
遥遥无期 2020-12-06 11:21

I\'m using

password_hash($password, PASSWORD_BCRYPT);

to encrypt passwords to store in a database. As I read, there\'s no length limit on

2条回答
  •  死守一世寂寞
    2020-12-06 11:26

    The result of BCrypt will always be a 60 character string. Limitless is only the input for the function, that means you do not (and should not) set a limit to the entered passwords.

    Actually BCrypt internally uses only about 72 characters, but it accepts passwords of any length.

    If you want to use the function in its future proof form like this (notice the PASSWORD_DEFAULT)...

    password_hash($password, PASSWORD_DEFAULT);
    

    ...then you should make your database field bigger. Newer PHP versions may replace BCrypt with another default hash algorithm, which may generate longer hashes.

提交回复
热议问题