Files
reflector-dashboard/auth/password_change.php
T

32 lines
1.1 KiB
PHP

<?php
/*
* Reflector Dashboard — web front-end for SvxReflector
* Copyright (C) 2026 SA7AUX (Björn)
* SPDX-License-Identifier: AGPL-3.0-or-later
*
* This program is free software: you can redistribute it and/or modify it under
* the terms of the GNU Affero General Public License as published by the Free
* Software Foundation, either version 3 of the License, or (at your option) any
* later version. See the LICENSE file for details.
*/
declare(strict_types=1);
require __DIR__ . '/lib.php';
$uuid = require_login();
csrf_check();
$j = json_in();
$old = (string)($j['old_password'] ?? '');
$new = (string)($j['new_password'] ?? '');
if ($old === '' || $new === '') json_out(['ok'=>false,'error'=>'missing_fields'], 400);
if (strlen($new) < 6) json_out(['ok'=>false,'error'=>'too_short'], 400);
$acct = acct_get($uuid);
$hash = (string)($acct['password_hash'] ?? '');
if ($hash === '' || !password_verify($old, $hash)) {
json_out(['ok'=>false,'error'=>'invalid_old_password'], 401);
}
redis()->hSet(acct_key($uuid), 'password_hash', password_hash($new, PASSWORD_DEFAULT));
json_out(['ok'=>true]);