How to securely generate SSHA256 or SSHA512 hashes in PHP?

前端 未结 2 744
说谎
说谎 2021-02-15 01:58

I am working on a web administration module for mailservers (it\'s open source if you\'d like to take a look).

For that, I need to be able to generate hashed password th

2条回答
  •  野趣味
    野趣味 (楼主)
    2021-02-15 02:47

    The Dovecot wiki page you linked to explains what the exact hash format Dovecot uses is. You don't have any choice in the matter -- Dovecot has its expectations on what the hash will look like, so you have to play by its rules:

    For most of the salted password schemes (SMD5, SSHA*) the salt is stored after the password hash and its length can vary. When hashing the password, append the salt after the plaintext password, e.g.: SSHA256(pass, salt) = SHA256(pass + salt) + salt.

    So an appropriate password generation function in PHP might look like:

    $hash = "{SSHA256}" . base64_encode(hash('sha256', $password . $salt) . $salt);
    

提交回复
热议问题