login/edit: password generation for user admins
authorMischa POSLAWSKY <perl@shiar.org>
Fri, 18 Oct 2019 19:22:25 +0000 (21:22 +0200)
committerMischa POSLAWSKY <perl@shiar.org>
Sat, 19 Oct 2019 00:26:35 +0000 (02:26 +0200)
Option to reset users of Lijtweg.

login/pass.inc.php

index 5b03c8090eedd5ff9ce198e4cea43f2cf7eb5466..61685fe1a7d57030cf49a460ce276a55922ac866 100644 (file)
@@ -1,6 +1,8 @@
 <?php
 function passform(&$user, $input = [])
 {
+       global $User;
+
        if (empty($user)) {
                return "Log eerst (opnieuw?) in.";
        }
@@ -10,7 +12,7 @@ function passform(&$user, $input = [])
                return "Het wachtwoord kan niet worden aangepast voor deze gebruiker.";
        }
 
-       if (!empty($user->pass)) {
+       if (!empty($user->pass) and !$User->admin('user') ) {
                if (empty($input['oldpass'])) {
                        return "Als extra beveiliging tegen ongewenste aanpassingen moet het bestaande wachtwoord worden ingevoerd.";
                }
@@ -20,23 +22,29 @@ function passform(&$user, $input = [])
                }
        }
 
-       if (empty($input['newpass'])) {
-               return "Geef een nieuw wachtwoord op.";
+       if ($input['newpass'] == 'GEN') {
+               $passstore = random_int(10000, 99999);
        }
+       else {
+               if (empty($input['newpass'])) {
+                       return "Geef een nieuw wachtwoord op.";
+               }
 
-       if (strlen($input['newpass']) < 4) {
-               return "Zo'n kort wachtwoord is een slecht idee.";
-       }
+               if (strlen($input['newpass']) < 4) {
+                       return "Zo'n kort wachtwoord is een slecht idee.";
+               }
 
-       if ($input['newpass'] == $user->login) {
-               return "De loginnaam is wel heel makkelijk raadbaar als wachtwoord.";
-       }
+               if ($input['newpass'] == $user->login) {
+                       return "De loginnaam is wel heel makkelijk raadbaar als wachtwoord.";
+               }
+
+               if ($input['newpass'] != $input['passconf']) {
+                       return "Zorg dat bij de bevestiging precies het zelfde wachtwoord staat.";
+               }
 
-       if ($input['newpass'] != $input['passconf']) {
-               return "Zorg dat bij de bevestiging precies het zelfde wachtwoord staat.";
+               $passstore = password_hash($input['newpass'], PASSWORD_DEFAULT);
        }
 
-       $passstore = password_hash($input['newpass'], PASSWORD_DEFAULT);
        if (empty($passstore) or !file_put_contents($pwfile, $passstore)) {
                return "Het nieuwe wachtwoord kon niet worden opgeslagen. Het oude wachtwoord is behouden.";
        }
@@ -45,7 +53,7 @@ function passform(&$user, $input = [])
 
        $authhash = md5($passstore);
        $user->auth = "{$user->login}:$authhash";
-       if ($GLOBALS['User'] === $user) {
+       if ($User === $user) {
                login_setcookie();
        }
        return;