The following files exists in this folder. Click to view.
changePassword.php77 lines UTF-8 Unix (LF) 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
<?php
include("check_session.php");
require_once("databaseconnection.php");
if(isset($_POST["oldPass"])){
$sql = "SELECT `password` FROM users WHERE `userId` = :userId LIMIT 1"; #kollar om inmatad e-post är upptagen
$stm = $pdo->prepare($sql);
$stm->execute([
':userId' => $_SESSION["userId"]
]);
$passInfo = $stm->fetchAll(PDO::FETCH_ASSOC);
if(password_verify($_POST["oldPass"], $passInfo[0]["password"])){
$freshAndCleanNewPassWordThatIsAbsolutelyAwesomeAndLKAHJDGIAJUKD = password_hash($_POST["newPass"], PASSWORD_DEFAULT);
$sql = "UPDATE users SET `password` = :password WHERE `userId` = :userId"; #kollar om inmatad e-post är upptagen
$stm = $pdo->prepare($sql);
$stm->execute([
':password' => $freshAndCleanNewPassWordThatIsAbsolutelyAwesomeAndLKAHJDGIAJUKD,
':userId' => $_SESSION["userId"]
]);
header("location:changePassword.php?mess=success");
exit();
}
else{
header("location:changePassword.php?mess=fail");
exit();
}
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Change Password</title>
<link rel="stylesheet" href="/spectre/spectre-master/dist/spectre.css">
<script src="https://kit.fontawesome.com/0b0c9a8dc7.js" crossorigin="anonymous"></script>
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Special+Gothic+Expanded+One&family=Special+Gothic:wght@400..700&display=swap" rel="stylesheet">
<style>
#navTop{
font-family: "Special Gothic Expanded One", Helvetica;
}
</style>
</head>
<body style="text-align:center;">
<header class="navbar">
<section class="navbar-section">
<a href="#" class="btn btn-link">Settings</a>
<a href="home.php" class="btn btn-link">Home</a>
</section>
<section class="navbar-center">
<h3 id="navTop">PHiNTERNET</h3>
</section>
<section class="navbar-section">
<a href="newpost.php" class="btn btn-link">Create Post</a>
<a href="profile.php?mess=<?php echo"{$_SESSION["userId"]}"?>" class="btn btn-link">Profile</a>
</section>
</header>
<h1>Change Password</h1>
<br><br><br>
<form method="post" action="?">
<label for="oldPass">Old password:</label>
<input id="oldPass" type="password" name="oldPass" required>
<br><br>
<label for="newPass">New password:</label>
<input id="newPass" type="password" name="newPass" required>
<br><br>
<input type="submit" class="btn btn-primary">
</form>
</body>
</html>