1
0
Fork 0

Use POST for password changes, validate input

master
Anonymous Contributor 2023-08-23 18:16:35 +02:00
parent c97c58e30d
commit 1df2182bae
1 changed files with 42 additions and 58 deletions

View File

@ -1,61 +1,45 @@
<?php <?php
if($_SERVER['REQUEST_TYPE'] == 'POST') {
if(!isset($_SESSION['LOGIN']) || !isset($_SESSION['UUID'])) {
header('Location: index.php');
die();
}
$HTML->setHTMLTitle("Passwort ändern"); include '../app/FormValidator.php';
$HTML->importSeitenInhalt("profile.html"); $validator = new FormValidator(array(
'oldPassword' => array('required' => true, 'regex' => '.{1,1000}'),
'newPassword' => array('required' => true, 'regex' => '.{1,1000}'),
'newPasswordRepeat' => array('required' => true, 'regex' => '.{1,1000}')
));
if(isset($_REQUEST['oldPassword']) || $_REQUEST['oldPassword'] != "") if($validator->isValid($_POST)) {
{ if($_POST['newPasswordRepeat'] == $_POST['newPassword']) {
$OLDPassword = trim($_REQUEST['oldPassword']); if(password_verify($_POST['oldPassword'], $_SESSION['PASSWORD'])) {
if($OLDPassword != "")
{
if(password_verify($OLDPassword, $_SESSION['PASSWORD']))
{
if(isset($_REQUEST['newPassword']) && $_REQUEST['newPassword'] != "")
{
$NewPassword = trim($_REQUEST['newPassword']);
if($NewPassword != "")
{
if(isset($_REQUEST['newPasswordRepeate']) || $_REQUEST['newPasswordRepeate'] != "")
{
$NewPasswordRepeate = trim($_REQUEST['newPasswordRepeate']);
if($NewPasswordRepeate != "")
{
if($NewPasswordRepeate == $NewPassword)
{
$hash = password_hash($NewPassword, PASSWORD_ARGON2ID); $hash = password_hash($NewPassword, PASSWORD_ARGON2ID);
$statement = $RUNTIME['PDO']->prepare('UPDATE auth SET passwordHash = :PasswordHash WHERE UUID = :PrincipalID'); $statement = $RUNTIME['PDO']->prepare('UPDATE auth SET passwordHash = :PasswordHash WHERE UUID = :PrincipalID');
$statement->execute(['PasswordHash' => $hash, 'PrincipalID' => $_SESSION['UUID']]); $statement->execute(['PasswordHash' => $hash, 'PrincipalID' => $_SESSION['UUID']]);
$_SESSION['PASSWORD'] = $hash; $_SESSION['PASSWORD'] = $hash;
$_SESSION['pwChanged'] = true; $_SESSION['pw_info'] = 'Neues Passwort gespeichert.';
}
else {
$_SESION['pw_info'] = 'Das alte Passwort ist nicht richtig!';
}
}
else {
$_SESSION['pw_info'] = 'Die neuen Passwörter stimmen nicht überein!';
}
}
else {
$_SESSION['pw_info'] = 'Bitte fülle das Formular vollständig aus.';
}
header('Location: index.php?page=password'); header('Location: index.php?page=password');
die(); die();
}else{
$HTML->ReplaceSeitenInhalt("%%INFOMESSAGE%%", 'Passwörter stimmen nicht überein!');
}
}else{
$HTML->ReplaceSeitenInhalt("%%INFOMESSAGE%%", 'Bitte gib das Passwort zur bestätigung noch einmal ein!');
}
}else{
$HTML->ReplaceSeitenInhalt("%%INFOMESSAGE%%", 'Bitte gib das Passwort zur bestätigung noch einmal ein!');
}
}else{
$HTML->ReplaceSeitenInhalt("%%INFOMESSAGE%%", 'Bitte gebe ein neues Passwort ein!');
}
}else{
$HTML->ReplaceSeitenInhalt("%%INFOMESSAGE%%", 'Bitte gebe ein neues Passwort ein!');
}
}else{
$HTML->ReplaceSeitenInhalt("%%INFOMESSAGE%%", 'Das alte Passwort ist nicht richtig!');
}
}else{
$HTML->ReplaceSeitenInhalt("%%INFOMESSAGE%%", 'Gebe bitte dein Passwort ein.');
}
} }
$HTML->setHTMLTitle("Passwort ändern");
$HTML->importSeitenInhalt("profile.html");
include 'app/OpenSim.php'; include 'app/OpenSim.php';
$opensim = new OpenSim(); $opensim = new OpenSim();
@ -70,12 +54,12 @@
$HTML->ReplaceSeitenInhalt("%%email%%", htmlspecialchars($opensim->getUserMail($_SESSION['UUID']))); $HTML->ReplaceSeitenInhalt("%%email%%", htmlspecialchars($opensim->getUserMail($_SESSION['UUID'])));
$HTML->ReplaceSeitenInhalt("%%listAllResidentsAsJSArray%%", ""); $HTML->ReplaceSeitenInhalt("%%listAllResidentsAsJSArray%%", "");
$pwChanged = false; $pwInfo = '';
if(isset($_SESSION['pwChanged'])) { if(isset($_SESSION['pw_info'])) {
$pwChanged = true; $pwInfo = $_SESSION['pw_info'];
unset($_SESSION['pwChanged']); unset($_SESSION['pw_info']);
} }
$HTML->ReplaceSeitenInhalt("%%INFOMESSAGE%%", $pwChanged ? 'Neues Passwort gespeichert.' : ' '); $HTML->ReplaceSeitenInhalt("%%INFOMESSAGE%%", $pwInfo);
$HTML->build(); $HTML->build();
echo $HTML->ausgabe(); echo $HTML->ausgabe();