fitness-api/html/login/index.php
2020-03-28 18:57:49 +01:00

34 lines
864 B
PHP

<?php
include "../../config.php";
session_start();
if (isset($_POST['username']) and isset($_POST['password'])){
$sql = "SELECT * FROM users WHERE username=?";
$stmt = $pdo->prepare($sql);
$stmt->bindParam(1, $_POST['username']);
if ($stmt->execute()){
$data = $stmt->fetchAll(PDO::FETCH_ASSOC)[0];
$password = $data['password'];
if (password_verify($_POST['password'], $password)){
$_SESSION['username'] = $data['username'];
$_SESSION['email'] = $data['email'];
header("Location: ../");
}
}
}
?>
<html>
<head>
</head>
<body>
<form method="post">
<input type="text" name="username" placeholder="Username" required><br>
<input type="password" name="password" placeholder="Password" required><br>
<button onclick="submit">log in</button>
</form>
</body>
</html>