1

Topic: Generate a password with php

==== Required information ====
- iRedMail version 0.9.6:
- Linux/BSD distribution name and version: Ubuntu 16.04.3 LTS
- Store mail accounts in which backend (LDAP/MySQL/PGSQL): MySQL
- Web server (Apache or Nginx): Nginx
- Manage mail accounts with iRedAdmin-Pro?
- [IMPORTANT] Related original log or error message is required if you're experiencing an issue.
====

Hello,

I am trying to generate a password with php

After two days of intense search on the generation of password with Dovecote, I have this code :

$password = 'test';
$salt = substr(str_replace('+','.',base64_encode(md5(mt_rand(), true))),0,8);
$hash = hash('sha512', $salt.$password, true).$salt;
$hashedPassword = "{SSHA512}" . base64_encode($hash);

echo $hashedPassword;

I copy / paste the hash into the database and can not connect. What is missing to get to generate a password in SSHA512?

La génération de mot de passe ne fonctionne pas non plus avec cette commande : doveadm pw -s SHA512-CRYPT....

Thanks for help.

C4Y

----

Spider Email Archiver: On-Premises, lightweight email archiving software developed by iRedMail team. Supports Amazon S3 compatible storage and custom branding.

2

Re: Generate a password with php

This should work very well:

$password = 'test';
$salt = random_str(8);
$hashed_password = hash('sha512', $password . $salt, true);
$password_to_db = '{SSHA512}' . base64_encode($hashed_password . $salt);