<?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('inc/error.php');
require_once('inc/base.php');
require_once('vendor/autoload.php');
function gen_pw_hash($password)
{
/* For yescrypt, a 128 bit salt in non-standard base64 is
needed. We just need random data with valid encoding. */
$salt = base64_encode(random_bytes(16));
$salt = rtrim($salt, "=");
$salt = strtr($salt, "AQgw+/01", "./01AQgw");
$pwhash = crypt($password, '$y$j9T$' . $salt);
if (strlen($pwhash) < 13) {
/* returns a string shorter than 13 chars on failure */
system_failure("Failed to calculate password hash!");
}
return $pwhash;
}
function legacy_pw_verify($password, $hash)
{
/* Supports legacy SHA1/SHA256 hashes without salt,
for new use cases use password_verify() instead */
if ($hash[0] == '$') {
return password_verify($password, $hash);
} elseif (strlen($hash) == 40) {
return hash_equals(sha1($password), $hash);
} elseif (strlen($hash) == 64) {
return hash_equals(hash("sha256", $password), $hash);
}
return false;
}
function strong_password($password, $user = [])
{
$pwcheck = config('pwcheck');