如何使用 sql 驱动程序和 mysql 使用随机盐加密设置圆形密码插件?

rda*_*rda 6 mysql linux php roundcube

我有一个安装和配置后缀的邮件服务器,如http://flurdy.com/docs/postfix/index.html。我使用带有两个maildb字段=和=的表的 mysql 数据库。使用如下查询更新密码:usersid'user@domain.com'crypt'salted_md5_hash'

UPDATE users SET crypt = ENCRYPT('apassword', CONCAT('$5$', MD5(RAND()))) WHERE id = 'user@domain.tld';
Run Code Online (Sandbox Code Playgroud)

Roundcube 1.0-RC 根据http://trac.roundcube.net/wiki/Howto_Install安装

如何设置 roundcube 密码插件以与上述安装一起使用?

rda*_*rda 9

编辑 roundcube mainconfig.inc.php并添加插件名称'password'到 plugins array() 中,如下所示,以激活插件:

// List of active plugins (in plugins/ directory)
$config['plugins'] = array('password');
Run Code Online (Sandbox Code Playgroud)

您还可以记下 roundcube 用于连接到 “roundcube” mysql 数据库$config['db_dsnw'] = 'mysql://user:pass@localhost/roundcube'

cd 进入.../roundcube_www_root/plugins/password/并创建config.inc.php

# cp config.inc.php.dist config.inc.php
# vi config.inc.php
Run Code Online (Sandbox Code Playgroud)

编辑密码插件中的以下几行 config.inc.php

<?php

$config['password_driver'] = 'sql';
$config['password_confirm_current'] = true;
$config['password_minimum_length'] = 8;
$config['password_require_nonalpha'] = false;
$config['password_log'] = false;
$config['password_login_exceptions'] = null;
// If the server is accessed via fqdn, replace localhost by the fqdn:
$config['password_hosts'] = array('127.0.0.1');
$config['password_force_save'] = true;

// SQL Driver options
$config['password_db_dsn'] = 'mysql://user:pass@localhost/maildb';

// SQL Update Query with encrypted password using random 8 character salt
$config['password_query'] = 'UPDATE users SET crypt=ENCRYPT(%p,CONCAT(_utf8\'$5$\',RIGHT(MD5(RAND()),8),_utf8\'$\')) WHERE id=%u LIMIT 1';

...
Run Code Online (Sandbox Code Playgroud)

要使用SHA-512密码哈希代替SHA-256,请将 设置$id$$6$(另请参见man 3 crypt):

$config['password_query'] = 'UPDATE users SET crypt=ENCRYPT(%p,CONCAT(_utf8\'$6$\',RIGHT(MD5(RAND()),8),_utf8\'$\')) WHERE id=%u LIMIT 1';
Run Code Online (Sandbox Code Playgroud)

.../plugins/password/README.../plugins/password/config.inc.php.dist了解更多信息。

假设你将使用相同的mysql用户的密码插件更新密码,你必须授予SELECTUPDATE在表上授权“用户”“MAILDB”“roundcube” MySQL用户:

# mysql -u root -p
mysql > GRANT SELECT,UPDATE ON maildb.users TO 'roundcube'@'localhost';
mysql > FLUSH PRIVILEGES;
mysql > quit
# 
Run Code Online (Sandbox Code Playgroud)

就是这样。如果遇到问题,拖尾roundcube错误日志:

# tail -f ../../logs/error
Run Code Online (Sandbox Code Playgroud)