6 changed files with 94 additions and 0 deletions
@ -0,0 +1,10 @@ |
|||||
|
<?php |
||||
|
|
||||
|
use App\Wrappers\TwigWrapper; |
||||
|
|
||||
|
require_once __DIR__ . "/../vendor/autoload.php"; |
||||
|
|
||||
|
TwigWrapper::RenderTwig( |
||||
|
target: "Pages/change-password.html.twig", |
||||
|
arguments: [], |
||||
|
); |
@ -0,0 +1,38 @@ |
|||||
|
<?php |
||||
|
|
||||
|
use App\Enumerators\SessionElement; |
||||
|
use App\Wrappers\CAPTCHAWrapper; |
||||
|
use App\Wrappers\DatabaseInteractions; |
||||
|
use App\Wrappers\SessionWrapper; |
||||
|
use App\Wrappers\SQLQueryBuilderWrapper; |
||||
|
use Ramsey\Uuid\Uuid; |
||||
|
|
||||
|
require_once __DIR__ . "/../../vendor/autoload.php"; |
||||
|
|
||||
|
|
||||
|
$captchaResponse = $_POST['g-recaptcha-response']; |
||||
|
CAPTCHAWrapper::HandleCaptchaResponse($captchaResponse); |
||||
|
|
||||
|
|
||||
|
if(!isset($_POST['Password1'])) die('No password'); |
||||
|
if(!isset($_POST['Password2'])) die('No confirm password'); |
||||
|
|
||||
|
if($_POST['Password1'] != $_POST['Password2']) die('Passwords do not match'); |
||||
|
|
||||
|
$sha512Hash = hash(algo: 'sha512', data: $_POST['Password1'], binary: false); |
||||
|
$hashedPassword = password_hash(password: $sha512Hash, algo: PASSWORD_BCRYPT); |
||||
|
|
||||
|
$db = new DatabaseInteractions(); |
||||
|
|
||||
|
$db->RunUpdate( |
||||
|
queryBuilder: SQLQueryBuilderWrapper::UPDATE( |
||||
|
table: 'Users', |
||||
|
) |
||||
|
->set(col: 'PasswordHash', value: ':__password_hash__') |
||||
|
->where('ID=:__user_id__') |
||||
|
->bindValue(name: '__user_id__', value: SessionWrapper::Get(SessionElement::USER_ID)) |
||||
|
->bindValue(name: '__password_hash__', value: $hashedPassword) |
||||
|
); |
||||
|
|
||||
|
header("Location: /profile"); |
||||
|
die(); |
@ -0,0 +1,39 @@ |
|||||
|
{% extends "/Bases/StandardWebPage.html.twig" %} |
||||
|
|
||||
|
{% block content %} |
||||
|
|
||||
|
|
||||
|
<script src="https://www.google.com/recaptcha/enterprise.js?render={{ _CAPTCHA_KEY_ID_ }}"></script> |
||||
|
<script> |
||||
|
function onSubmitChangePasswordForm(token) { |
||||
|
document.getElementById("ChangePasswordForm").submit(); |
||||
|
} |
||||
|
</script> |
||||
|
|
||||
|
<div class="InnerContent"> |
||||
|
<h1>{{ "Change Password"|translate }}</h1> |
||||
|
<form |
||||
|
id="ChangePasswordForm" |
||||
|
action="/FormHandling/ChangePassword.php" |
||||
|
method="POST" |
||||
|
> |
||||
|
|
||||
|
<label for="Password1">{{ "New Password"|translate }}</label> |
||||
|
<br> |
||||
|
<input id="Password1" name="Password1" type="password"> |
||||
|
|
||||
|
<br> |
||||
|
|
||||
|
<label for="Password2">{{ "Confirm New Password"|translate }}</label> |
||||
|
<br> |
||||
|
<input id="Password2" name="Password2" type="password"> |
||||
|
|
||||
|
<br> |
||||
|
|
||||
|
<button class="g-recaptcha" |
||||
|
data-sitekey="{{ _CAPTCHA_KEY_ID_ }}" |
||||
|
data-callback='onSubmitChangePasswordForm' |
||||
|
data-action='submit'>{{ "Change Password"|translate }}</button> |
||||
|
</form> |
||||
|
</div> |
||||
|
{% endblock %} |
Loading…
Reference in new issue