mirror of
https://codeberg.org/ThisIsMiseryy/techstore
synced 2026-05-14 14:52:04 +00:00
62 lines
2.1 KiB
PHP
62 lines
2.1 KiB
PHP
<!DOCTYPE html>
|
|
<html lang="it">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<title>Login - TechStore</title>
|
|
<link rel="stylesheet" href="assets/style.css">
|
|
</head>
|
|
<body>
|
|
<?php
|
|
session_start();
|
|
include 'db_conf.php';
|
|
|
|
$error = '';
|
|
|
|
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
|
$email = $_POST['email'];
|
|
$password = $_POST['password'];
|
|
|
|
$sql = "SELECT Name, Password, Role FROM Users WHERE Email = ?";
|
|
if ($stmt = $conn->prepare($sql)) {
|
|
$stmt->bind_param("s", $email);
|
|
$stmt->execute();
|
|
$stmt->store_result();
|
|
|
|
if ($stmt->num_rows > 0) {
|
|
$stmt->bind_result($name, $hashed_password, $role);
|
|
$stmt->fetch();
|
|
|
|
if (password_verify($password, $hashed_password)) {
|
|
$_SESSION['user'] = $name;
|
|
$_SESSION['role'] = $role;
|
|
header('Location: index.php');
|
|
exit();
|
|
} else {
|
|
$error = 'Credenziali errate.';
|
|
}
|
|
} else {
|
|
$error = 'Credenziali errate.';
|
|
}
|
|
|
|
$stmt->close();
|
|
} else {
|
|
$error = 'Errore nel database.';
|
|
}
|
|
}
|
|
?>
|
|
<form action="" method="POST">
|
|
<h2>Login</h2>
|
|
<label for="email">Indirizzo e-mail:</label>
|
|
<input type="email" id="email" name="email" required><br>
|
|
<label for="password">Password:</label>
|
|
<input type="password" id="password" name="password" required><br>
|
|
<?php if ($error): ?>
|
|
<p style="color: red; text-align: center;"><?php echo htmlspecialchars($error); ?></p>
|
|
<?php endif; ?>
|
|
<br>
|
|
<button type="submit">Login</button>
|
|
<p style="text-align: center;">Non hai un account? <a href="register.php">Registrati</a></p>
|
|
</form>
|
|
</body>
|
|
</html>
|