login: indicate failure in http status codes
[minimedit.git] / login / pass.inc.php
index 483f8bbb72aac517ea03d47f9a523a822e0aa404..59679048eda00ef3f7341638524b75f8d03c42e0 100644 (file)
@@ -6,7 +6,7 @@ function passform($user, $input = [])
        }
 
        $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.";
        }
 
@@ -36,7 +36,8 @@ function passform($user, $input = [])
                return "Zorg dat bij de bevestiging precies het zelfde wachtwoord staat.";
        }
 
-       if (!file_put_contents($pwfile, $input['newpass'])) {
+       $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.";
        }