Init commit
This commit is contained in:
45
index.php
Normal file
45
index.php
Normal file
@@ -0,0 +1,45 @@
|
||||
<?php
|
||||
|
||||
require_once __DIR__ . '/classes/MyDB.php';
|
||||
|
||||
$title = 'SQLite';
|
||||
$res = '';
|
||||
$name = $_POST['name'];
|
||||
$pass = $_POST['pass'];
|
||||
|
||||
if ($name === '' || $pass === '') {
|
||||
$res = 'All strings required!';
|
||||
unset($_POST);
|
||||
}
|
||||
|
||||
if ($_POST['submit'] === 'OK') {
|
||||
global $db;
|
||||
$result = $db->query("SELECT * FROM users WHERE name = '$name'");
|
||||
$auth = $result->fetchArray();
|
||||
|
||||
if ($auth['name'] !== $name || password_verify($pass, $auth['pass']) !== true) {
|
||||
$res = 'Login or password is wrong!';
|
||||
}
|
||||
session_start();
|
||||
$_SESSION['name'] = $auth['name'];
|
||||
$_SESSION['id'] = $auth['id'];
|
||||
header("Location: secret.php");
|
||||
exit();
|
||||
}
|
||||
?>
|
||||
|
||||
<?php require_once 'templates/header.php'; ?>
|
||||
|
||||
<body>
|
||||
<div class="auth">
|
||||
<h1>Authorization</h1>
|
||||
<form action="/" method="post">
|
||||
<p><input type="text" name="name" id="name" placeholder="Login"></p>
|
||||
<p><input type="password" name="pass" id="pass" placeholder="Password"></p>
|
||||
<p class="error"><?= $res; ?></p>
|
||||
<p><input type="submit" value="OK" name="submit"></p>
|
||||
</form>
|
||||
<p><a href="registration.php">Registration</a></p>
|
||||
</div>
|
||||
|
||||
<?php include_once 'templates/footer.php'; ?>
|
||||
Reference in New Issue
Block a user