Login and Auth
This commit is contained in:
21
assets/php/login.php
Normal file
21
assets/php/login.php
Normal file
@@ -0,0 +1,21 @@
|
||||
<?php
|
||||
session_start();
|
||||
require 'db.php';
|
||||
|
||||
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
|
||||
$username = htmlspecialchars($_POST['username']);
|
||||
$password = $_POST['password'];
|
||||
|
||||
$stmt = $pdo->prepare("SELECT * FROM users WHERE username = ?");
|
||||
$stmt->execute([$username]);
|
||||
$user = $stmt->fetch();
|
||||
|
||||
if ($user && password_verify($password, $user['password'])) {
|
||||
$_SESSION['user_id'] = $user['id'];
|
||||
$_SESSION['username'] = $user['username'];
|
||||
echo 'success';
|
||||
} else {
|
||||
echo 'Invalid login credentials';
|
||||
}
|
||||
}
|
||||
?>
|
||||
Reference in New Issue
Block a user