1
0
mirror of https://github.com/delight-im/PHP-Auth.git synced 2025-08-09 17:46:33 +02:00

2 Commits

Author SHA1 Message Date
Marco
e7e174b05d Only configure and start session if not already started 2018-03-12 22:29:56 +01:00
Marco
8f35cc9965 Optimize spacing in PostgreSQL schema 2018-03-12 18:44:32 +01:00
2 changed files with 12 additions and 15 deletions

View File

@@ -25,9 +25,7 @@ CREATE TABLE IF NOT EXISTS "users_confirmations" (
"token" VARCHAR(255) NOT NULL, "token" VARCHAR(255) NOT NULL,
"expires" INTEGER NOT NULL CHECK ("expires" >= 0) "expires" INTEGER NOT NULL CHECK ("expires" >= 0)
); );
CREATE INDEX IF NOT EXISTS "email_expires" ON "users_confirmations" ("email", "expires"); 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 INDEX IF NOT EXISTS "user_id" ON "users_confirmations" ("user_id");
CREATE TABLE IF NOT EXISTS "users_remembered" ( CREATE TABLE IF NOT EXISTS "users_remembered" (
@@ -37,7 +35,6 @@ CREATE TABLE IF NOT EXISTS "users_remembered" (
"token" VARCHAR(255) NOT NULL, "token" VARCHAR(255) NOT NULL,
"expires" INTEGER NOT NULL CHECK ("expires" >= 0) "expires" INTEGER NOT NULL CHECK ("expires" >= 0)
); );
CREATE INDEX IF NOT EXISTS "user" ON "users_remembered" ("user"); CREATE INDEX IF NOT EXISTS "user" ON "users_remembered" ("user");
CREATE TABLE IF NOT EXISTS "users_resets" ( CREATE TABLE IF NOT EXISTS "users_resets" (
@@ -47,7 +44,6 @@ CREATE TABLE IF NOT EXISTS "users_resets" (
"token" VARCHAR(255) NOT NULL, "token" VARCHAR(255) NOT NULL,
"expires" INTEGER NOT NULL CHECK ("expires" >= 0) "expires" INTEGER NOT NULL CHECK ("expires" >= 0)
); );
CREATE INDEX IF NOT EXISTS "user_expires" ON "users_resets" ("user", "expires"); CREATE INDEX IF NOT EXISTS "user_expires" ON "users_resets" ("user", "expires");
CREATE TABLE IF NOT EXISTS "users_throttling" ( CREATE TABLE IF NOT EXISTS "users_throttling" (
@@ -56,7 +52,6 @@ CREATE TABLE IF NOT EXISTS "users_throttling" (
"replenished_at" INTEGER NOT NULL CHECK ("replenished_at" >= 0), "replenished_at" INTEGER NOT NULL CHECK ("replenished_at" >= 0),
"expires_at" INTEGER NOT NULL CHECK ("expires_at" >= 0) "expires_at" INTEGER NOT NULL CHECK ("expires_at" >= 0)
); );
CREATE INDEX IF NOT EXISTS "expires_at" ON "users_throttling" ("expires_at"); CREATE INDEX IF NOT EXISTS "expires_at" ON "users_throttling" ("expires_at");
COMMIT; COMMIT;

View File

@@ -48,7 +48,7 @@ final class Auth extends UserManager {
$this->sessionResyncInterval = isset($sessionResyncInterval) ? ((int) $sessionResyncInterval) : (60 * 5); $this->sessionResyncInterval = isset($sessionResyncInterval) ? ((int) $sessionResyncInterval) : (60 * 5);
$this->rememberCookieName = self::createRememberCookieName(); $this->rememberCookieName = self::createRememberCookieName();
$this->initSession(); $this->initSessionIfNecessary();
$this->enhanceHttpSecurity(); $this->enhanceHttpSecurity();
$this->processRememberDirective(); $this->processRememberDirective();
@@ -56,16 +56,18 @@ final class Auth extends UserManager {
} }
/** Initializes the session and sets the correct configuration */ /** Initializes the session and sets the correct configuration */
private function initSession() { private function initSessionIfNecessary() {
// use cookies to store session IDs if (\session_status() === \PHP_SESSION_NONE) {
\ini_set('session.use_cookies', 1); // use cookies to store session IDs
// use cookies only (do not send session IDs in URLs) \ini_set('session.use_cookies', 1);
\ini_set('session.use_only_cookies', 1); // use cookies only (do not send session IDs in URLs)
// do not send session IDs in URLs \ini_set('session.use_only_cookies', 1);
\ini_set('session.use_trans_sid', 0); // do not send session IDs in URLs
\ini_set('session.use_trans_sid', 0);
// start the session (requests a cookie to be written on the client) // start the session (requests a cookie to be written on the client)
@Session::start(); @Session::start();
}
} }
/** Improves the application's security over HTTP(S) by setting specific headers */ /** Improves the application's security over HTTP(S) by setting specific headers */