PHP Encrypt like SQL for Dovecot

265 views Asked by At

I'm running Dovecot + Postfix on my server, and I want PHP to generate e-mail accounts. It all works, except the password. They are using a MySQL-function, but I cannot use it because I use Symfony (at least I think I cannot easily use it)

ENCRYPT('password', CONCAT('$6$', SUBSTRING(SHA(RAND()), -16)))

And I want to 'convert' this function a PHP script. I've tried this, but with no luck:

$fp = fopen('/dev/urandom', 'r');
$randomString = fread($fp, 32);
fclose($fp);
$salt = base64_encode($randomString);

$email->setPassword(crypt($email->getPlainPassword(), '$6$'.$salt));

Thanks in advance, Bart

1

There are 1 answers

1
Bart Wesselink On

After more trying, I found this:

$salt = substr(sha1(lcg_value ()), -16);
$email->setPassword(crypt($email->getPlainPassword(), '$6$'.$salt));