mirror of
https://github.com/delight-im/PHP-Auth.git
synced 2025-08-08 17:16:29 +02:00
Compare commits
6 Commits
Author | SHA1 | Date | |
---|---|---|---|
|
142ccc362f | ||
|
bce31f9cfc | ||
|
3ddc7af1b4 | ||
|
62d9e44aa4 | ||
|
1121685cef | ||
|
2f9bab4779 |
62
Database/PostgreSQL.sql
Normal file
62
Database/PostgreSQL.sql
Normal file
@@ -0,0 +1,62 @@
|
|||||||
|
-- PHP-Auth (https://github.com/delight-im/PHP-Auth)
|
||||||
|
-- Copyright (c) delight.im (https://www.delight.im/)
|
||||||
|
-- Licensed under the MIT License (https://opensource.org/licenses/MIT)
|
||||||
|
|
||||||
|
BEGIN;
|
||||||
|
|
||||||
|
CREATE TABLE IF NOT EXISTS "users" (
|
||||||
|
"id" SERIAL PRIMARY KEY CHECK ("id" >= 0),
|
||||||
|
"email" VARCHAR(249) UNIQUE NOT NULL,
|
||||||
|
"password" VARCHAR(255) NOT NULL,
|
||||||
|
"username" VARCHAR(100) DEFAULT NULL,
|
||||||
|
"status" SMALLINT NOT NULL DEFAULT '0' CHECK ("status" >= 0),
|
||||||
|
"verified" SMALLINT NOT NULL DEFAULT '0' CHECK ("verified" >= 0),
|
||||||
|
"resettable" SMALLINT NOT NULL DEFAULT '1' CHECK ("resettable" >= 0),
|
||||||
|
"roles_mask" INTEGER NOT NULL DEFAULT '0' CHECK ("roles_mask" >= 0),
|
||||||
|
"registered" INTEGER NOT NULL CHECK ("registered" >= 0),
|
||||||
|
"last_login" INTEGER DEFAULT NULL CHECK ("last_login" >= 0)
|
||||||
|
);
|
||||||
|
|
||||||
|
CREATE TABLE IF NOT EXISTS "users_confirmations" (
|
||||||
|
"id" SERIAL PRIMARY KEY CHECK ("id" >= 0),
|
||||||
|
"user_id" INTEGER NOT NULL CHECK ("user_id" >= 0),
|
||||||
|
"email" VARCHAR(249) NOT NULL,
|
||||||
|
"selector" VARCHAR(16) UNIQUE NOT NULL,
|
||||||
|
"token" VARCHAR(255) NOT NULL,
|
||||||
|
"expires" INTEGER NOT NULL CHECK ("expires" >= 0)
|
||||||
|
);
|
||||||
|
|
||||||
|
CREATE INDEX IF NOT EXISTS "email_expires" ON "users_confirmations" ("email", "expires");
|
||||||
|
|
||||||
|
CREATE INDEX IF NOT EXISTS "user_id" ON "users_confirmations" ("user_id");
|
||||||
|
|
||||||
|
CREATE TABLE IF NOT EXISTS "users_remembered" (
|
||||||
|
"id" BIGSERIAL PRIMARY KEY CHECK ("id" >= 0),
|
||||||
|
"user" INTEGER NOT NULL CHECK ("user" >= 0),
|
||||||
|
"selector" VARCHAR(24) UNIQUE NOT NULL,
|
||||||
|
"token" VARCHAR(255) NOT NULL,
|
||||||
|
"expires" INTEGER NOT NULL CHECK ("expires" >= 0)
|
||||||
|
);
|
||||||
|
|
||||||
|
CREATE INDEX IF NOT EXISTS "user" ON "users_remembered" ("user");
|
||||||
|
|
||||||
|
CREATE TABLE IF NOT EXISTS "users_resets" (
|
||||||
|
"id" BIGSERIAL PRIMARY KEY CHECK ("id" >= 0),
|
||||||
|
"user" INTEGER NOT NULL CHECK ("user" >= 0),
|
||||||
|
"selector" VARCHAR(20) UNIQUE NOT NULL,
|
||||||
|
"token" VARCHAR(255) NOT NULL,
|
||||||
|
"expires" INTEGER NOT NULL CHECK ("expires" >= 0)
|
||||||
|
);
|
||||||
|
|
||||||
|
CREATE INDEX IF NOT EXISTS "user_expires" ON "users_resets" ("user", "expires");
|
||||||
|
|
||||||
|
CREATE TABLE IF NOT EXISTS "users_throttling" (
|
||||||
|
"bucket" VARCHAR(44) PRIMARY KEY,
|
||||||
|
"tokens" REAL NOT NULL CHECK ("tokens" >= 0),
|
||||||
|
"replenished_at" INTEGER NOT NULL CHECK ("replenished_at" >= 0),
|
||||||
|
"expires_at" INTEGER NOT NULL CHECK ("expires_at" >= 0)
|
||||||
|
);
|
||||||
|
|
||||||
|
CREATE INDEX IF NOT EXISTS "expires_at" ON "users_throttling" ("expires_at");
|
||||||
|
|
||||||
|
COMMIT;
|
10
README.md
10
README.md
@@ -18,9 +18,9 @@ Completely framework-agnostic and database-agnostic.
|
|||||||
|
|
||||||
* PHP 5.6.0+
|
* PHP 5.6.0+
|
||||||
* PDO (PHP Data Objects) extension (`pdo`)
|
* PDO (PHP Data Objects) extension (`pdo`)
|
||||||
* MySQL Native Driver (`mysqlnd`) **or** SQLite driver (`sqlite`)
|
* MySQL Native Driver (`mysqlnd`) **or** PostgreSQL driver (`pgsql`) **or** SQLite driver (`sqlite`)
|
||||||
* OpenSSL extension (`openssl`)
|
* OpenSSL extension (`openssl`)
|
||||||
* MySQL 5.5.3+ **or** MariaDB 5.5.23+ **or** SQLite 3.14.1+ **or** other SQL databases that you create the [schema](Database) for
|
* MySQL 5.5.3+ **or** MariaDB 5.5.23+ **or** PostgreSQL 9.5.10+ **or** SQLite 3.14.1+ **or** [other SQL databases](Database)
|
||||||
|
|
||||||
## Installation
|
## Installation
|
||||||
|
|
||||||
@@ -38,7 +38,9 @@ Completely framework-agnostic and database-agnostic.
|
|||||||
|
|
||||||
1. Set up a database and create the required tables:
|
1. Set up a database and create the required tables:
|
||||||
|
|
||||||
|
* [MariaDB](Database/MySQL.sql)
|
||||||
* [MySQL](Database/MySQL.sql)
|
* [MySQL](Database/MySQL.sql)
|
||||||
|
* [PostgreSQL](Database/PostgreSQL.sql)
|
||||||
* [SQLite](Database/SQLite.sql)
|
* [SQLite](Database/SQLite.sql)
|
||||||
|
|
||||||
## Upgrading
|
## Upgrading
|
||||||
@@ -96,12 +98,16 @@ Migrating from an earlier version of this project? See our [upgrade guide](Migra
|
|||||||
```php
|
```php
|
||||||
// $db = new \PDO('mysql:dbname=my-database;host=localhost;charset=utf8mb4', 'my-username', 'my-password');
|
// $db = new \PDO('mysql:dbname=my-database;host=localhost;charset=utf8mb4', 'my-username', 'my-password');
|
||||||
// or
|
// or
|
||||||
|
// $db = new \PDO('pgsql:dbname=my-database;host=localhost;port=5432', 'my-username', 'my-password');
|
||||||
|
// or
|
||||||
// $db = new \PDO('sqlite:../Databases/my-database.sqlite');
|
// $db = new \PDO('sqlite:../Databases/my-database.sqlite');
|
||||||
|
|
||||||
// or
|
// or
|
||||||
|
|
||||||
// $db = new \Delight\Db\PdoDsn('mysql:dbname=my-database;host=localhost;charset=utf8mb4', 'my-username', 'my-password');
|
// $db = new \Delight\Db\PdoDsn('mysql:dbname=my-database;host=localhost;charset=utf8mb4', 'my-username', 'my-password');
|
||||||
// or
|
// or
|
||||||
|
// $db = new \Delight\Db\PdoDsn('pgsql:dbname=my-database;host=localhost;port=5432', 'my-username', 'my-password');
|
||||||
|
// or
|
||||||
// $db = new \Delight\Db\PdoDsn('sqlite:../Databases/my-database.sqlite');
|
// $db = new \Delight\Db\PdoDsn('sqlite:../Databases/my-database.sqlite');
|
||||||
|
|
||||||
$auth = new \Delight\Auth\Auth($db);
|
$auth = new \Delight\Auth\Auth($db);
|
||||||
|
@@ -29,6 +29,8 @@ require __DIR__.'/../vendor/autoload.php';
|
|||||||
|
|
||||||
$db = new \PDO('mysql:dbname=php_auth;host=127.0.0.1;charset=utf8mb4', 'root', 'monkey');
|
$db = new \PDO('mysql:dbname=php_auth;host=127.0.0.1;charset=utf8mb4', 'root', 'monkey');
|
||||||
// or
|
// or
|
||||||
|
// $db = new \PDO('pgsql:dbname=php_auth;host=127.0.0.1;port=5432', 'postgres', 'monkey');
|
||||||
|
// or
|
||||||
// $db = new \PDO('sqlite:../Databases/php_auth.sqlite');
|
// $db = new \PDO('sqlite:../Databases/php_auth.sqlite');
|
||||||
|
|
||||||
$auth = new \Delight\Auth\Auth($db);
|
$auth = new \Delight\Auth\Auth($db);
|
||||||
|
Reference in New Issue
Block a user