admin/pass: form to change current password
authorMischa POSLAWSKY <perl@shiar.org>
Fri, 22 Dec 2017 22:49:13 +0000 (23:49 +0100)
committerMischa POSLAWSKY <perl@shiar.org>
Fri, 22 Dec 2017 22:57:04 +0000 (23:57 +0100)
admin/pass.html [new file with mode: 0644]
admin/pass.php [new file with mode: 0644]
auth.inc.php

diff --git a/admin/pass.html b/admin/pass.html
new file mode 100644 (file)
index 0000000..751f230
--- /dev/null
@@ -0,0 +1 @@
+<h2>Wachtwoord wijzigen</h2>
diff --git a/admin/pass.php b/admin/pass.php
new file mode 100644 (file)
index 0000000..829aff4
--- /dev/null
@@ -0,0 +1,61 @@
+<?php
+if ($_POST) {
+       $error = passform($_POST);
+       if (empty($error)) {
+               print "<p>Het wachtwoord is aangepast. Voortaan met het nieuwe wachtwoord inloggen.</p>\n\n";
+               return;
+       }
+       print "<p class=warn>$error</p>\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;
+}
+
+?>
+<form method="post">
+<p>
+<input type="password" name="oldpass" value="" placeholder="Huidig wachtwoord" />
+<input type="password" name="newpass" value="" placeholder="Nieuw wachtwoord" />
+<input type="submit" value="Wijzig" />
+</p>
+</form>
index fd11b1353a1dfe1feaa82dc81bad675cc714a9ea..48b81fcd2e05e779681d5f89e886c453d30de9ba 100644 (file)
@@ -45,7 +45,9 @@ function login($inuser, $inpass = NULL)
 
        return [
                'name'  => $inuser,
+               'dir'   => $userdir,
                'admin' => file_exists("$userdir/.admin"),
+               'pass'  => $usertest,
                'auth'  => "$inuser:$authhash",
        ];
 }