From 5e936f812affead3fb1b4c86cc90590d6ec7a953 Mon Sep 17 00:00:00 2001 From: Mischa POSLAWSKY Date: Fri, 22 Dec 2017 23:49:13 +0100 Subject: [PATCH] admin/pass: form to change current password --- admin/pass.html | 1 + admin/pass.php | 61 +++++++++++++++++++++++++++++++++++++++++++++++++ auth.inc.php | 2 ++ 3 files changed, 64 insertions(+) create mode 100644 admin/pass.html create mode 100644 admin/pass.php diff --git a/admin/pass.html b/admin/pass.html new file mode 100644 index 0000000..751f230 --- /dev/null +++ b/admin/pass.html @@ -0,0 +1 @@ +

Wachtwoord wijzigen

diff --git a/admin/pass.php b/admin/pass.php new file mode 100644 index 0000000..829aff4 --- /dev/null +++ b/admin/pass.php @@ -0,0 +1,61 @@ +Het wachtwoord is aangepast. Voortaan met het nieuwe wachtwoord inloggen.

\n\n"; + return; + } + print "

$error

\n\n"; +} + +function passform($input = []) +{ + global $User; + + if (empty($User)) { + return "Log eerst (opnieuw?) in."; + } + + $pwfile = "{$User['dir']}/.passwd"; + if (!is_writable($pwfile)) { + return "Het wachtwoord kan niet worden aangepast voor deze gebruiker."; + } + + if (empty($_POST['oldpass'])) { + return "Als extra beveiliging tegen ongewenste aanpassingen moet het bestaande wachtwoord worden ingevoerd."; + } + + if (empty($_POST['newpass'])) { + return "Geef ook een nieuw wachtwoord op."; + } + + if (strlen($_POST['newpass']) < 4) { + return "Zo'n kort wachtwoord is een slecht idee."; + } + + if ($_POST['newpass'] == $User['name']) { + return "De loginnaam is wel heel makkelijk raadbaar als wachtwoord."; + } + + if (!login_password_verify($_POST['oldpass'], $User['pass'])) { + return "Het bestaande wachtwoord is onjuist ingevoerd; niet aangepast."; + } + + if (!file_put_contents($pwfile, $_POST['newpass'])) { + return "Het nieuwe wachtwoord kon niet worden opgeslagen. Het oude wachtwoord is behouden."; + } + + $authhash = md5($_POST['newpass']); + $User['auth'] = "{$User['name']}:$authhash"; + login_setcookie(); + return; +} + +?> +
+

+ + + +

+
diff --git a/auth.inc.php b/auth.inc.php index fd11b13..48b81fc 100644 --- a/auth.inc.php +++ b/auth.inc.php @@ -45,7 +45,9 @@ function login($inuser, $inpass = NULL) return [ 'name' => $inuser, + 'dir' => $userdir, 'admin' => file_exists("$userdir/.admin"), + 'pass' => $usertest, 'auth' => "$inuser:$authhash", ]; } -- 2.30.0