wscore / auth
a simple authenticate package.
Installs: 24
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 0
Open Issues: 2
pkg:composer/wscore/auth
Requires (Dev)
- phpunit/phpunit: ^8.0
This package is not auto-updated.
Last update: 2025-10-26 01:22:30 UTC
README
A simple authentication package.
License
MIT License
PSR
PSR-1, PSR-2, and PSR-4.
Installation
composer require "wscore/auth: ^0.3"
Getting Started
Auth requires UserProviderInterface object to access to user information.
$auth = new Auth(new UserProvider);
To authenticate a user, get user-id ($id) and user-password ($pw) from a login form, and
if ($auth->login($id, $pw)) { echo 'login success!'; }
to check for login later on,
$auth->isLogin();
You can retrieve login information such as;
$user = $auth->getLoginUser(); // login user entity returned by UserProvider's getUserInfo() method. $mail = $auth->getLoginId(); // get login user's id. maybe an email?
Force Login
forceLogin method allow to login as a user without a password,
for purposes, such as system administration.
$auth->forceLogin($id);
then, you can check if the login is force or not.
$auth->isLoginBy(Auth::BY_FORCED); // check for login method.
UserProvider
The Auth requires a user provider object implementing UserProviderInterface.
The interface has 4 APIs; that are
- getUserById($id): for retrieving a user entity for- $id(a login user).
- getUserByIdAndPw($id, $pw): for retrieving a user entity for- $idand valid- $pw.
- getUserType(): for retrieving a key-string to identify the user-provider.
Remember-Me Option
To use Remember-me option, use setRememberMe method, as
$auth = new Auth(...); $auth->setRememberMe(new MyRememberMe());
- $rememberobject implementing- RememberMeInterface,
- RememberCookieobject,
then, when login, supply 3rd argument when login as
$auth->login($id, $pw, true);
to save the $id and a remember-me token to cookie if login is successful.