account/change-password refactor a bit

Add "The old password is same as the new password!"
Better post variables names
This commit is contained in:
slawkens
2025-10-16 21:36:14 +02:00
parent 470555f268
commit 16849e7578
2 changed files with 13 additions and 11 deletions

View File

@@ -19,18 +19,17 @@ if(!$logged) {
csrfProtect();
$new_password = $_POST['newpassword'] ?? NULL;
$new_password_confirm = $_POST['newpassword_confirm'] ?? NULL;
$old_password = $_POST['oldpassword'] ?? NULL;
$new_password = $_POST['new_password'] ?? null;
$new_password_confirm = $_POST['new_password_confirm'] ?? null;
$old_password = $_POST['old_password'] ?? null;
if(empty($new_password) && empty($new_password_confirm) && empty($old_password)) {
$twig->display('account.change-password.html.twig');
}
else
{
else {
if(empty($new_password) || empty($new_password_confirm) || empty($old_password)){
$errors[] = 'Please fill in form.';
}
$password_strlen = strlen($new_password);
if($new_password != $new_password_confirm) {
$errors[] = 'The new passwords do not match!';
}
@@ -41,10 +40,13 @@ else
}
/** @var OTS_Account $account_logged */
$old_password = encrypt((USE_ACCOUNT_SALT ? $account_logged->getCustomField('salt') : '') . $old_password);
if($old_password != $account_logged->getPassword()) {
$old_password_hashed = encrypt((USE_ACCOUNT_SALT ? $account_logged->getCustomField('salt') : '') . $old_password);
if($old_password_hashed != $account_logged->getPassword()) {
$errors[] = 'Current password is incorrect!';
}
else if ($old_password == $new_password) {
$errors[] = 'The old password is same as the new password!';
}
$hooks->trigger(HOOK_ACCOUNT_CHANGE_PASSWORD_POST);
}

View File

@@ -9,7 +9,7 @@ Please enter your current password and a new password. For your security, please
<span>Current Password:</span>
</td>
<td>
<input form="form" type="password" name="oldpassword" size="30" maxlength="29">
<input form="form" type="password" id="old_password" name="old_password" size="30" maxlength="29">
</td>
</tr>
@@ -20,7 +20,7 @@ Please enter your current password and a new password. For your security, please
<span>New Password:</span>
</td>
<td style="width:90%;">
<input form="form" type="password" name="newpassword" size="30" maxlength="29">
<input form="form" type="password" id="new_password" name="new_password" size="30" maxlength="29">
</td>
</tr>
@@ -31,7 +31,7 @@ Please enter your current password and a new password. For your security, please
<span>New Password Again:</span>
</td>
<td>
<input form="form" type="password" name="newpassword_confirm" size="30" maxlength="29">
<input form="form" type="password" id="new_password_confirm" name="new_password_confirm" size="30" maxlength="29">
</td>
</tr>
</table>