简体   繁体   English

使用php和doveadm创建密码

[英]Using php and doveadm to create password

I've created an registration page in php with an mysql backend. 我已经在mysql后端的php中创建了一个注册页面。 If the user is entering his new password it should become SHA512-CRYPT via doveadm. 如果用户正在输入新密码,则该密码应通过doveadm变为SHA512-CRYPT。

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: 但是由于我的邮件服务器,我想用doveadm创建密码哈希:

$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? 但这似乎不起作用,如何在php中实现此“ doveadm”命令?

您必须使用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 避免使用shell_exec是危险的,如果您在示例中使用dovecot的默认配置作为命令,则dovecot会生成带有16个字符(字节)的盐的哈希值,因此,您可以使用php函数crypt来产生相同的结果结果,您将避免使用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 将为您提供与doveadm pw命令兼容的结果

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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