init
This commit is contained in:
@@ -0,0 +1,72 @@
|
||||
<?php
|
||||
require_once 'includes/db.php';
|
||||
require_once 'includes/auth.php';
|
||||
checkAuth();
|
||||
|
||||
$message = '';
|
||||
|
||||
if ($_SERVER["REQUEST_METHOD"] == "POST") {
|
||||
$old_pass = $_POST['old_password'];
|
||||
$new_pass = $_POST['new_password'];
|
||||
$confirm_pass = $_POST['confirm_password'];
|
||||
|
||||
if ($new_pass !== $confirm_pass) {
|
||||
$message = '<div class="alert alert-danger">Nowe hasła nie są identyczne!</div>';
|
||||
} else {
|
||||
// Pobierz aktualne hasło z bazy
|
||||
$stmt = $pdo->prepare("SELECT password FROM " . DB_PREFIX . "users WHERE id = ?");
|
||||
$stmt->execute([$_SESSION['user_id']]);
|
||||
$user = $stmt->fetch();
|
||||
|
||||
if (password_verify($old_pass, $user['password'])) {
|
||||
// Hasło poprawne - aktualizujemy
|
||||
$new_hash = password_hash($new_pass, PASSWORD_BCRYPT);
|
||||
$update = $pdo->prepare("UPDATE " . DB_PREFIX . "users SET password = ? WHERE id = ?");
|
||||
$update->execute([$new_hash, $_SESSION['user_id']]);
|
||||
$message = '<div class="alert alert-success">Hasło zostało zmienione pomyślnie!</div>';
|
||||
} else {
|
||||
$message = '<div class="alert alert-danger">Obecne hasło jest nieprawidłowe.</div>';
|
||||
}
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
||||
<!DOCTYPE html>
|
||||
<html lang="pl">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>Zmiana hasła - <?php echo APP_NAME; ?></title>
|
||||
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">
|
||||
</head>
|
||||
<body class="bg-light">
|
||||
<div class="container py-5">
|
||||
<div class="card shadow mx-auto" style="max-width: 450px;">
|
||||
<div class="card-header bg-dark text-white">
|
||||
<h5 class="mb-0">Zmiana hasła</h5>
|
||||
</div>
|
||||
<div class="card-body">
|
||||
<?php echo $message; ?>
|
||||
<form method="POST">
|
||||
<div class="mb-3">
|
||||
<label class="form-label">Obecne hasło</label>
|
||||
<input type="password" name="old_password" class="form-control" required>
|
||||
</div>
|
||||
<hr>
|
||||
<div class="mb-3">
|
||||
<label class="form-label">Nowe hasło</label>
|
||||
<input type="password" name="new_password" class="form-control" required minlength="5">
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label class="form-label">Powtórz nowe hasło</label>
|
||||
<input type="password" name="confirm_password" class="form-control" required>
|
||||
</div>
|
||||
<div class="d-flex justify-content-between">
|
||||
<a href="index.php" class="btn btn-secondary">Powrót</a>
|
||||
<button type="submit" class="btn btn-primary">Zmień hasło</button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
Reference in New Issue
Block a user