<?php
require 'database.php';
$nickname = trim($_POST['nickname']); $errors[] = 'You forgot to enter your nickname.';
}
$password = trim($_POST['password']); $errors[] = 'You forgot to enter your old password.';
}
$new_password = trim($_POST['new_password']); $verify_password = trim($_POST['new_confirm_password']); if (!empty($new_password)) { if (($new_password != $verify_password) ||
( $password == $new_password ))
{
$errors[] = 'Your new password did not match the confirmed password and/or ';
$errors[] = 'Your old password is the same as your new password.';
}
} else {
$errors[] = 'You did not enter a new password.';
}
try {
$query = "SELECT id, password FROM users WHERE ( nickname=:nickname )";
$result = mysqli_stmt_get_result($q);
if ((mysqli_num_rows($result) == 1) && (password_verify
($password, $row['password']))) { $hashed_passcode = password_hash($new_password, PASSWORD_BCRYPT);
$query = "UPDATE users SET password=:password WHERE nickname=:nickname";
header ("location: passwordThanks.php"); } else {
$errorstring = "System Error! <br /> You could not change password due ";
$errorstring .= "to a system error. We apologize for any inconvenience.</p>";
echo "<p>$errorstring</p>";
echo '<footer class="jumbotron text-center col-sm-12" style="padding-bottom:1px; padding-top:8px;"> include("footer.php"); </footer>';
}
} else {
$errorstring = 'Error! <br /> ';
$errorstring .= 'The nickname and/or password do not match those on file.';
$errorstring .= " Please try again.";
echo "<p>$errorstring</p>";
}
} catch(Exception $e) {
print "The system is busy please try later";
} catch(Error $e) {
print "The system is busy please try again later.";
}
} else {
$errorstring = "Error! The following error(s) occurred:<br>";
foreach ($errors as $msg) {
$errorstring .= " - $msg<br>\n";
}
$errorstring .= "Please try again.<br>";
echo "<p>$errorstring</p>";
}
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Change your Password</title>
<link href="https://fonts.googleapis.com/css?family=Roboto" rel="stylesheet">
<link rel="stylesheet" href="assets/css/style.css"/>
</head>
<body>
<?php require "partials/header.php" ?>
<?php if (!empty($message)): ?> <p><?= $message ?></p>
<?php endif; ?>
<h1>Change your Password</h1>
<form action="changePassword.php" method="post">
<input type="text" name="nickname" placeholder="Enter your nickname">
<input type="password" name="old_password" placeholder="Enter your old password">
<input type="password" name="new_password" placeholder="Enter your new password">
<input type="password" name="new_confirm_password" placeholder="Confirm your new password">
<input type="submit" value="Send">
</body>
<footer class="jumbotron text-center row" style="padding-bottom:1px; padding-top:8px;">
<?php
require 'partials/footer.php'
?>
</footer>
</html>