mirror of
https://codeberg.org/ThisIsMiseryy/techstore
synced 2026-05-14 12:42:04 +00:00
Implementazione pagina cambio password
This commit is contained in:
+2
-2
@@ -49,8 +49,8 @@ if ($result === false) {
|
|||||||
<h1>Account di <?php echo htmlspecialchars($_SESSION['name']); ?><?php if ($_SESSION['role'] == 'admin') { echo ' (Admin)'; } ?></h1>
|
<h1>Account di <?php echo htmlspecialchars($_SESSION['name']); ?><?php if ($_SESSION['role'] == 'admin') { echo ' (Admin)'; } ?></h1>
|
||||||
<p><strong>Nome completo:</strong> <?php echo htmlspecialchars($_SESSION['name']) . ' ' . htmlspecialchars($_SESSION['surname']); ?></p>
|
<p><strong>Nome completo:</strong> <?php echo htmlspecialchars($_SESSION['name']) . ' ' . htmlspecialchars($_SESSION['surname']); ?></p>
|
||||||
<br>
|
<br>
|
||||||
<a href="passwordChange.php" style="padding: 8px 16px; background-color: #17a2b8; color: white; border: none; border-radius: 4px; text-decoration: none; cursor: pointer;">Modifica password</a>
|
<a href="account/passwordChange.php" style="padding: 8px 16px; background-color: #17a2b8; color: white; border: none; border-radius: 4px; text-decoration: none; cursor: pointer;">Modifica password</a>
|
||||||
<a href="deleteAccount.php" style="padding: 8px 16px; background-color: #dc3545; color: white; border: none; border-radius: 4px; text-decoration: none; cursor: pointer;">Elimina account</a>
|
<a href="account/delete.php" style="padding: 8px 16px; background-color: #dc3545; color: white; border: none; border-radius: 4px; text-decoration: none; cursor: pointer;">Elimina account</a>
|
||||||
<br><br>
|
<br><br>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -0,0 +1,90 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="it">
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8">
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
|
<title>Cambio Password - TechStore</title>
|
||||||
|
<link rel="stylesheet" href="../assets/style.css">
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<?php
|
||||||
|
session_start();
|
||||||
|
include '../db_conf.php';
|
||||||
|
|
||||||
|
if (!isset($_SESSION['id'])) {
|
||||||
|
header('Location: ../login.php');
|
||||||
|
exit();
|
||||||
|
}
|
||||||
|
|
||||||
|
$message = '';
|
||||||
|
$error = '';
|
||||||
|
|
||||||
|
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
||||||
|
$current_password = $_POST['current_password'] ?? '';
|
||||||
|
$new_password = $_POST['new_password'] ?? '';
|
||||||
|
$confirm_password = $_POST['confirm_password'] ?? '';
|
||||||
|
|
||||||
|
if (empty($current_password) || empty($new_password) || empty($confirm_password)) {
|
||||||
|
$error = 'Compila tutti i campi.';
|
||||||
|
} elseif ($new_password !== $confirm_password) {
|
||||||
|
$error = 'La nuova password e la conferma non coincidono.';
|
||||||
|
} elseif (strlen($new_password) < 8) {
|
||||||
|
$error = 'La nuova password deve avere almeno 8 caratteri.';
|
||||||
|
} else {
|
||||||
|
$sql = "SELECT Password FROM Users WHERE UserID = ?";
|
||||||
|
if ($stmt = $conn->prepare($sql)) {
|
||||||
|
$stmt->bind_param("i", $_SESSION['id']);
|
||||||
|
$stmt->execute();
|
||||||
|
$stmt->bind_result($hashed_password);
|
||||||
|
$stmt->fetch();
|
||||||
|
$stmt->close();
|
||||||
|
|
||||||
|
if (!password_verify($current_password, $hashed_password)) {
|
||||||
|
$error = 'La password corrente non è corretta.';
|
||||||
|
} else {
|
||||||
|
$new_hashed = password_hash($new_password, PASSWORD_DEFAULT);
|
||||||
|
$sql_update = "UPDATE Users SET Password = ? WHERE UserID = ?";
|
||||||
|
if ($stmt_update = $conn->prepare($sql_update)) {
|
||||||
|
$stmt_update->bind_param("si", $new_hashed, $_SESSION['id']);
|
||||||
|
$stmt_update->execute();
|
||||||
|
$stmt_update->close();
|
||||||
|
|
||||||
|
$message = 'Password aggiornata con successo.';
|
||||||
|
} else {
|
||||||
|
$error = 'Errore durante l\'aggiornamento della password.';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
$error = 'Errore nel database.';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
?>
|
||||||
|
|
||||||
|
<form action="" method="POST">
|
||||||
|
<h2>Cambio Password</h2>
|
||||||
|
<?php if ($message): ?>
|
||||||
|
<p style="color: #155724; background-color: #d4edda; border: 1px solid #c3e6cb; padding: 10px; border-radius: 4px; text-align: center;">
|
||||||
|
<?php echo htmlspecialchars($message); ?>
|
||||||
|
</p>
|
||||||
|
<?php endif; ?>
|
||||||
|
<?php if ($error): ?>
|
||||||
|
<p style="color: #721c24; background-color: #f8d7da; border: 1px solid #f5c6cb; padding: 10px; border-radius: 4px; text-align: center;">
|
||||||
|
<?php echo htmlspecialchars($error); ?>
|
||||||
|
</p>
|
||||||
|
<?php endif; ?>
|
||||||
|
|
||||||
|
<label for="current_password">Password corrente:</label>
|
||||||
|
<input type="password" id="current_password" name="current_password" required><br>
|
||||||
|
|
||||||
|
<label for="new_password">Nuova password:</label>
|
||||||
|
<input type="password" id="new_password" name="new_password" required><br>
|
||||||
|
|
||||||
|
<label for="confirm_password">Conferma nuova password:</label>
|
||||||
|
<input type="password" id="confirm_password" name="confirm_password" required><br>
|
||||||
|
|
||||||
|
<button type="submit">Aggiorna password</button>
|
||||||
|
<p style="text-align: center;"><a href="../account.php">Torna al mio account</a></p>
|
||||||
|
</form>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
Reference in New Issue
Block a user