gmail-roundcube/rootfs/var/www/plugins/password/drivers/file.php
Knut Ahlers c5d3eade69
Switch to own build from upstream roundcube
Signed-off-by: Knut Ahlers <knut@ahlers.me>
2018-09-11 15:04:12 +02:00

18 lines
672 B
PHP

<?php
class rcube_file_password
{
function save($curpass, $passwd)
{
$userfile = getenv('ROUNDCUBE_USER_FILE');
$user = $_SESSION['username'];
$salt = sha1(rand());
$salt = substr($salt, 0, 4);
$hash = '{SSHA}' . base64_encode(sha1($passwd . $salt, true) . $salt);
$content = file_get_contents($userfile);
$content = preg_replace('/^' . preg_quote($user, '/') . ':.*$/m', "{$user}:{$hash}", $content, 1, $count);
if($count != 1)
return PASSWORD_ERROR;
$result = file_put_contents($userfile, $content);
return $result === false ? PASSWORD_ERROR : PASSWORD_SUCCESS;
}
}