larakeeps/authguard-otp
Composer 安装命令:
composer require larakeeps/authguard-otp
包简介
AuthGuard OTP is a package intended for random code generation, validation and confirmation (OTP).
关键字:
README 文档
README
AuthGuard OTP
AuthGuard OTP is a package intended for random code generation, validation and confirmation (OTP). Normally the OTP is used with a validator code or token that is sent by email or SMS to authenticate or authorize a certain action in the project.
This repository is only compatible with laravel: 7.* to 11.*
Installation
First Step, execute the command.
composer require larakeeps/authguard-otp
Second step, run the migration to create the tables: auth_guard_otp_codes
php artisan migrate
Third step, publish the authguard configuration, to publish the configurations run the command below:
php artisan vendor:publish --tag=authguard-otp-config
Generating otp code
use Larakeeps\AuthGuard\Facades\OTP; /** * * The create method has 3 parameters, 1 mandatory and 2 optional. * * The $reference parameter is used with the assertive condition function in code validation. * The $email parameter is used in the same way as the $reference parameter * * @param string $phone : required * @param string $email : optional * @param string $reference : optional * * @method static OTP create(string $phone, string|null $email, string|null $reference) * * */ $createOTP = OTP::create('phone number', 'email', 'reference'); // To retrieve the method return, call the following methods below. /** * * The then method returns 2 parameters, $data of type AuthGuard, and $response of type Collection. * * @method then(Closure $destination) * * */ $createOTP->then(function (AuthGuard|null $data, Collection $response){ /* * the $data parameter returns the null or Authguard model containing the table columns. */ /* * The $response parameter returns a collection containing the following data: * number_digits, code, message, status, user.access_token, user.ip_address */ return $data->expires_at; // returns a value of type Carbon::class; if($response->status){ return $response->message; } }); // OR through the get() method that returns a Collection return $createOTP->get(); // OR like this return OTP::get(); // OR through the getResponse() method that returns a Collection return $createOTP->getResponse(); // OR like this return OTP::getResponse(); // OR can be called individually using methods return OTP::getData()->expires_at; // returns a value of type Carbon::class; if(OTP::getStatus()){ return OTP::getMessage(); } return OTP::getAccessToken(); return OTP::getIpAddress();
Checking for the existence of generated code and viewing the generated data.
use Larakeeps\AuthGuard\Facades\OTP; /** * * Method to check if the generated code exists. * $phone parameter is used for better code verification assertiveness. * * @method static bool hasCode(string $code, string|null $phone) * * */ $hasCode = OTP::hasCode('154896'); if($hasCode){ return "The code exist." } /** * * Method for finding and returning data. * $phone parameter is used for better code verification assertiveness. * * @method static OTP getByCode(string $code, string|null $phone) * * */ $authGuardFounded = OTP::getByCode('154896', '5521985642205'); if($authGuardFounded){ return $authGuardFounded }
Confirm whether the code entered is valid and whether it was actually confirmed.
use Larakeeps\AuthGuard\Facades\OTP; /** * * The create method has 3 parameters, 2 mandatory and 1 optional. * * The $reference parameter is used with the assertive condition function in code validation. * * @param string $code : required * @param string $phone : required * @param string $reference : optional * * @method static OTP confirm(string $code, string $phone, string|null $reference) * * */ $validateCode = OTP::confirm('154896', '5521985642205'); // To retrieve the method return, call the following methods below. /** * * The then method returns 2 parameters, $data of type AuthGuard, and $response of type Collection. * * @method then(Closure $destination) * * */ $validateCode->then(function (null $data, Collection $response){ /* * * Within the confirm() method, the $data parameter will always return a null value. * * The $response parameter returns a collection containing the following data: * number_digits, code, message, status, user.access_token, user.ip_address */ if($response->status && OTP::isConfirmed()){ return $response->message; } return $response->message; }); // OR through the getResponse() method that returns a Collection return $createOTP->getResponse(); // OR like this return OTP::getResponse(); // OR can be called individually using methods if(OTP::getStatus()){ return OTP::getMessage(); } return OTP::getAccessToken(); return OTP::getIpAddress();
Deleting an OTP code.
use Larakeeps\AuthGuard\Facades\OTP; /** * * @method OTP deleteCode(string $code) * * */ $deletedCode = OTP::deleteCode(); // To retrieve the method return, call the following methods below. /** * * The then method returns 2 parameters, $data of type AuthGuard, and $response of type Collection. * * @method then(Closure $destination) * * */ $validateCode->then(function (null $data, Collection $response){ /* * * Within the deleteCode() method, the $data parameter will always return a null value. * * The $response parameter returns a collection containing the following data: * number_digits, code, message, status, user.access_token, user.ip_address */ if($response->status){ return $response->message; } }); // OR through the getResponse() method that returns a Collection return $createOTP->getResponse(); // OR like this return OTP::getResponse(); // OR can be called individually using methods if(OTP::getStatus()){ return OTP::getMessage(); } return OTP::getAccessToken(); return OTP::getIpAddress();
Don't forget to follow me on github and star the project.
My contacts
E-mail: douglassantos2127@gmail.com
Linkedin: Acessa Perfil
larakeeps/authguard-otp 适用场景与选型建议
larakeeps/authguard-otp 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 70 次下载、GitHub Stars 达 2, 最近一次更新时间为 2024 年 02 月 03 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「security」 「sms」 「code」 「validation」 「acl」 「laravel」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 larakeeps/authguard-otp 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 larakeeps/authguard-otp 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 larakeeps/authguard-otp 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Memio's PrettyPrinter, used to generate PHP code from given Model
Provide a way to secure accesses to all routes of an symfony application.
It's a barebone security class written on PHP
SDK for payment gateway PlatbaMobilom.sk for PHP7.0
Extensible library for building notifications and sending them via different delivery channels.
Promotional Codes Generator for Laravel 5.1
统计信息
- 总下载量: 70
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 2
- 点击次数: 20
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2024-02-03