- PHP ^7.0
- Login (customization)
The recommended way to install simple-auth is through Composer.
> composer require ryodevz/simple-auth
config/simpleauth.php
<?php
return [
'auth' => [
'login' => [
'base' => '/login.php',
'fields' => [
'btnLogin' => 'btn-login',
'username' => 'username',
'password' => 'password'
],
'redirect' => [
'success' => '/',
],
'password_hash' => false
]
],
'database' => [
'host' => 'localhost',
'username' => 'root',
'password' => null,
'database' => 'root',
'users_table' => [
'table' => 'users',
'username' => 'email',
'password' => 'password',
]
],
];
Auth::sessionStart()
login.php
<?php
use Ryodevz\Auth;
include 'vendor/autoload.php';
Auth::sessionStart();
Auth::login();
if (Auth::user()->username) {
return header('location: /');
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Login</title>
</head>
<body>
<small style="color: red;"><?= Auth::error() ?></small>
<form action="" method="post">
<table>
<tr>
<td>Username</td>
<td>:</td>
<td><input type="text" name="username" placeholder="Username"></td>
</tr>
<tr>
<td>Password</td>
<td>:</td>
<td><input type="password" name="password" placeholder="Password"></td>
</tr>
</table>
<button type="submit" name="btn-login" value="true">Login</button>
</form>
</body>
</html>