<?php
/*
This file belongs to the Webinterface of schokokeks.org Hosting
Written by schokokeks.org Hosting, namely
Bernd Wurst <bernd@schokokeks.org>
Hanno Böck <hanno@schokokeks.org>
This code is published under a 0BSD license.
Nevertheless, in case you use a significant part of this code, we ask (but not require, see the license) that you keep the authors' names in place and return your changes to the public. We would be especially happy if you tell us what you're going to do with this code.
*/
require_once('vendor/autoload.php');
function account_has_totp($username)
{
$result = db_query("SELECT id FROM mail.webmail_totp WHERE email=?", [$username]);
if ($result->rowCount() > 0) {
$tmp = $result->fetch();
$id = $tmp['id'];
return $id;
} else {
return false;
}
}
function validate_password($username, $password)
{
$args[":username"] = $username;
$result = db_query("SELECT account, cryptpass FROM mail.courier_mailaccounts WHERE account=:username UNION SELECT account, cryptpass FROM mail.courier_virtual_accounts WHERE account=:username", $args);
if ($result->rowCount() != 1) {
// Kein Account mit dem Namen oder Name nicht eindeutig
return false;
}
$account = $result->fetch();
return password_verify($password, $account['cryptpass']);
}
function store_webmail_password($username, $oldpw, $newpw)
{
$qual = strong_password($newpw);
if ($qual !== true) {
system_failure('Fehler beim Webmail-Passwort: ' . $qual);
}
$secret = $newpw;
if (strlen($oldpw) > strlen($newpw)) {
$secret = str_pad($newpw, strlen($oldpw), $newpw);