<?php
# admin/pswChange.php
require_once("restrictAccessToPage.php");
if(isset($_POST['psw'])){ # existir psw
require_once("connection.php");
$psw=sha1($_POST['psw']);
$idUsername=$_SESSION['idUsername'];
$sql="SELECT idPsw FROM psw
WHERE psw = '$psw' AND idUsername = $idUsername";
$query=mysqli_query($con, $sql) or die ($sql);
$total=mysqli_num_rows($query);
if($total==1){ # não autorizado
$path="?naoAutorizado";
} else { # autorizado
$sql="INSERT INTO psw (idUsername, psw) VALUES ($idUsername, '$psw')";
require("logSQL.php");
$path="?pswAlterada";
}
header("Location:$path");
}
?>
<!DOCTYPE html>
<html lang="en">
<?php require_once("head.php");?>
<body>
<?php require_once("navTop.php");?>
<div id="layoutSidenav">
<?php require_once("navSide.php");?>
<div id="layoutSidenav_content">
<main>
<div class="container-fluid px-4">
<h1 class="mt-4">Backoffice</h1>
<ol class="breadcrumb mb-4">
<li class="breadcrumb-item"><a href="cPanel.php">Control Panel</a></li>
<li class="breadcrumb-item active">Change password</li>
</ol>
<div class="card mb-4">
<div class="card-body">
<div class="mb-0">
<?php if(isset($_GET['naoAutorizado'])) {?>
<div class="alert alert-warning alert-dismissible fade show" role="alert"> <strong>System Warning!</strong> Password já foi utilizada. <button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>
</div>
<?php } ?>
<?php if(isset($_GET['pswAlterada'])) {?>
<div class="alert alert-success alert-dismissible fade show" role="alert"> <strong>Success!</strong> Password alterada com sucesso.
</div>
<?php } ?>
<?php if(!isset($_GET['pswAlterada'])) {?>
<form method="post" autocomplete="off">
<div class="form-floating mb-3">
<input required name="psw" class="form-control" id="inputPsw" type="password" autofocus/>
<label for="inputPsw">New password</label>
</div>
<div class="d-flex align-items-center justify-content-between mt-4 mb-0">
<button type="submit" class="btn btn-primary">Change Password</button>
</div>
</form>
<?php } ?>
</div>
</div>
</div>
<div style="height: 100vh"></div>
<div class="card mb-4"><div class="card-body">When scrolling, the navigation stays at the top of the page. This is the end of the static navigation demo.</div></div>
</div>
</main>
<?php require_once("footer.php");?>
</div>
</div>
<?php require_once("script.php");?>
</body>
</html>
Sem comentários:
Enviar um comentário