login/pass: set user cookie after token reset
[minimedit.git] / login / pass.inc.php
index cbfb1db9205a10a4eff22fe3e8c6b00bc5d4a7dd..986b4c262a91d4b8e8515c14423f24726bb027a0 100644 (file)
@@ -1,12 +1,12 @@
 <?php
-function passform($user, $input = [])
+function passform(&$user, $input = [])
 {
        if (empty($user)) {
                return "Log eerst (opnieuw?) in.";
        }
 
        $pwfile = "{$user['dir']}/.passwd";
-       if (!is_writable($pwfile)) {
+       if (file_exists($pwfile) and !is_writable($pwfile)) {
                return "Het wachtwoord kan niet worden aangepast voor deze gebruiker.";
        }
 
@@ -32,13 +32,18 @@ function passform($user, $input = [])
                return "De loginnaam is wel heel makkelijk raadbaar als wachtwoord.";
        }
 
-       if (!file_put_contents($pwfile, $input['newpass'])) {
+       if ($input['newpass'] != $input['passconf']) {
+               return "Zorg dat bij de bevestiging precies het zelfde wachtwoord staat.";
+       }
+
+       $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.";
        }
 
        @unlink("{$user['dir']}/.token"); # invalidate reset token
 
-       $authhash = md5($input['newpass']);
+       $authhash = md5($passstore);
        $user['auth'] = "{$user['name']}:$authhash";
        if ($GLOBALS['User'] === $user) {
                login_setcookie();