alantiller/authenticator

一个简单、轻量级且安全的认证类。

v1.2.1 2022-10-14 21:37 UTC

This package is auto-updated.

Last update: 2024-09-19 23:57:14 UTC


README

这是一个简单、安全且易于使用的认证库。我感觉目前还没有一个简单易用的库可以实现完全自定义的认证,所以我决定编写这个库。

安装

安装此库分为两步:首先是物理库的安装,然后是数据库的安装。

通过composer安装

安装很简单

composer install alantiller/authenticator

数据库安装

创建实例

$auth = new AlanTiller/Authenticator($pdo);

会话认证

登录

$auth->session()->login($email, $password)

检查

登出

用户管理

获取用户

$result = $auth->user()->get($id);

获取我

$result = $auth->user()->me();
$result = $auth->user()->create([
    "firstname" => "John",
    "surname" => "Smith",
    "email" => "johnsmith@example.com",
    "password" => "Pa33w0rd@1",
    "confirm_email" => 0, #set this to 1 if you want the email to confirm without having to send an email
]);

本库中有两种认证类型:会话和令牌。会话认证

self::createRandomString(16) -> TokenGenerator::generateToken(16)

createUserInternal -> createUser

// 获取当前用户

// 登录

// 登录 $auth->token()->login($email, $password)

// 登出 $auth->auth($token)

// 检查当前认证 $auth->auth()->check();

// 检查令牌认证 $auth->auth()->check($token);

// 检查当前权限 $auth->permission-