使用php和doveadm创建密码

I've created an registration page in php with an mysql backend. If the user is entering his new password it should become SHA512-CRYPT via doveadm.

This is what I have now,

$password=hash('sha256', $pass);

But I want to create a password hash with doveadm because of my mail server:

$password=(/usr/bin/doveadm pw -s SHA512-CRYPT -p "$pass")

But it doesn't seem to work, how can i implement this "doveadm" command in php?

You must call it with shell_exec method:

$password = shell_exec('/usr/bin/doveadm pw -s SHA512-CRYPT -p '. $pass);

Avoid to use shell_exec is dangerous, if you use the default config of dovecot as the command on your example then the dovecot produces a hash with a 16 chars (bytes) salt, as a result you can use the php function crypt to produce the same result and you will avoid the use of shell_exec

see below example

echo crypt("1234567890",'$6$Wh4t3v3rS4ltH3re'); //$6$ This part declares the SHA 512 and after the second $ must be 16 chars salt

will give you compatible result with the doveadm pw command