简体   繁体   中英

Using php and doveadm to create password

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?

您必须使用shell_exec方法调用它:

$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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM