定制 aliarefavin/avinauthpackage 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

aliarefavin/avinauthpackage

Composer 安装命令:

composer require aliarefavin/avinauthpackage

包简介

Custom authentication system for Laravel

README 文档

README

A lightweight and customizable Laravel package for verifying mobile/email using one-time passwords (OTP) on Redis.

🔐 Secure & Simple    •    📦 Easily Integrates with Laravel    •    ✉️ SMS/Email Ready

Verify your user mobile/email with a one-time password using both Redis and Mysql Database.

Installation

You can install the package via composer:

composer require aliarefavin/avinauthpackage
php artisan migrate

Publish config file using:

php artisan vendor:publish --tag=avinauth-config

Configuration

Configuration is located at config/avinauthconfig.php. Here's what you can adjust:

connection: you can set your connection to redis or database as you wish

Note: The default connection is redis and we recommend to keep it that way specially for large scale projects. If you are not using redis on your project and want to use database connection make sure to run php artisan migrate after installing the package.

code: OTP code generation rules.

resend_delay : Time delay (in seconds) before allowing another resend.

max_attemps: Maximum verification attempts allowed.

max_resends: Total resends allowed in one hour.

Usage

Send code to the user

use AliArefAvin\AvinAuthPackage\Services\AvinAuthService;


$result = (new AvinAuthService())->sendOTP($mobile, $request, $class);
        // Check if the request was successful
        if ($result['success'] && !array_key_exists('seconds', $result)) {
            // If the request was successful and the 'seconds' key is not present in the result,
            // set the 'seconds' key to the configured resend delay time
            $result['seconds'] = config('avinauthconfig.resend_delay');
        }
        // Return the result array, which contains information about the request status
        return $result;

$class is your class that implements AliArefAvin\AvinAuthPackage\Contracts\AvinAuthInterface

this $class contains your custom function named send that you use to send the code for users (email|sms) for exmaple your $class will be new AuthenticateService()

namespace App\Services\Auth;

use AliArefAvin\AvinAuthPackage\Contracts\AvinAuthInterface;

class AuthenticateService implements AvinAuthInterface
{
    public function send(string $receiver, string $code)
    {
        try {
            $Message = 'کد ورود شما:' . PHP_EOL .
                "code: $code" . PHP_EOL ;
                // If the receiver is not in the list of test numbers, send the SMS notification
                Notification::route(NotifyType::TSMS, []) // Set the notification route for SMS
                ->notify(
                    new SendSmsNotification( // Create a new SMS notification
                        $receiver, // The receiver's mobile number
                        $Message // The message content
                    )
                );
            return true; // Return true if the message was sent successfully
        } catch (Exception $e) {
            // If there is an exception (e.g., sending fails), return false
            return false; // Indicate that sending the code failed
        }
    }
}

Verify

You can verify code with request validation.

$request->validate([
    'mobile' => ['required'],
    'code' => 'required|avin_verify:mobile',
]);

mobile is your receiver which in this case is mobile.

Note: You can verify a code just once. so if you need to check code in two different requests then you should use something like the session to handle that.

Credits & Inspiration 🙌

  • This package is heavily inspired by the excellent work of the Sanjab Verify package. Special thanks to the Sanjab team for their elegant design and contribution to the Laravel ecosystem.

Contributing 🛠️

Contributions are welcome!

  • Fork the Project
  • Create a new branch
  • Add your changes
  • Submit a pull request 🙌

License 📝

This project is open-sourced under the MIT license.

aliarefavin/avinauthpackage 适用场景与选型建议

aliarefavin/avinauthpackage 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 905 次下载、GitHub Stars 达 1, 最近一次更新时间为 2025 年 04 月 07 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「Authentication」 「validation」 「auth」 「laravel」 「opt」 「authenticate」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 aliarefavin/avinauthpackage 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 aliarefavin/avinauthpackage 我们能提供哪些服务?
定制开发 / 二次开发

基于 aliarefavin/avinauthpackage 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 905
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 1
  • 点击次数: 20
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 1
  • Watchers: 1
  • Forks: 1
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-04-07