承接 signaturetech/laravel-otp 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

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

signaturetech/laravel-otp

最新稳定版本:1.0.5

Composer 安装命令:

composer require signaturetech/laravel-otp

包简介

A package to generate and manage otp

README 文档

README

Laravel

LaravelOtp : generate OTP and Validate OTP

GitHub Packagist Downloads

Table of contents

Introduction

LaravelOtp is a Laravel package, designed to generate OTP and Validate OTP using simple steps. This packages will show all OTP history.

Todo

  • Generate OTP
  • Verify OTP
  • Methods
  • OTP Lists
  • Test Cases

Features

  • Generate OTP
  • Verify OTP
  • Get the User OTP List
  • Generate custom lenth, expiry and formate OTP

Installation & Configuration

You can install this package via composer using:

composer require signaturetech/laravel-otp

Next run the command below to setup api-response.config file, you can set your configuration.

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

Now add the use SignatureTech\LaravelOtp\Traits\Otpable trait to your model.

use SignatureTech\LaravelOtp\Traits\Otpable;

class User extends Authenticatable
{
    use HasApiTokens, HasFactory, Notifiable, Otpable;
}

Generate OTP

Please use below code to generate otp:

  1. Get User Details
use App\Models\User;

$user = User::first();
  1. Create Otp Instance
use SignatureTech\LaravelOtp\Otp;


$otp = Otp::for($user->email)->generate();

Note: You can use email/mobile/phone number to generate otp Just pass the detail using for method.

Note: You can use more method to setting otp all methods described in methods section.

  1. Attach Otp with user
$userOtp = $user->createOtp($otp);

$otp = $user->otp;

Verify OTP

You can verify otp by using below code:

  1. Get the use details
use App\Models\User;

$user = User::first();
  1. Get Otp Instance
use SignatureTech\LaravelOtp\Otp;


$otp = Otp::for($user->email)->getOtp();
  1. Verify Otp
try {
    $user->verifyOtp($otp, $request->get('otp'));
} catch (OtpInvalidException $e) {
    return $e->getMessage;
} catch (OtpExpiredException $e) {
    return $e->getMessage;
}

Create OTP without model

You can also create otp without model using the following:

  1. Create OTP
use SignatureTech\LaravelOtp\Otp;


$otp = Otp::for($user->email)->create();

Note: You can use email/mobile/phone number to generate otp Just pass the detail using for method.

Note: You can use more method to setting otp all methods described in methods section.

  1. Verify Otp
try {
    $otp->verifyOtp($request->get('otp'));
} catch (OtpInvalidException $e) {
    return $e->getMessage;
} catch (OtpExpiredException $e) {
    return $e->getMessage;
}

Methods

  1. Set length of otp
use SignatureTech\LaravelOtp\Otp;

// Set Length of OTP
$otp = Otp::for($user->email)->setLength(4)->generate();

Note: Default length is 6 digit and you can change the default digit to add the OTP_LENGTH=4 in .env or config/otp.php file

  1. Set Format (Available Format: alpha | alphanumeric | numeric)
use SignatureTech\LaravelOtp\Otp;

// Set Format (Available Format: alpha | alphanumeric | numeric)
$otp = Otp::for($user->email)->setFormat('numeric')->generate();

Note: Default format is numeric and you can change the default format to add the OTP_FORMAT=4 in .env or config/otp.php file

  1. Set Expiry (In minutes)
use SignatureTech\LaravelOtp\Otp;

// Set Format (Available Format: alpha | alphanumeric | numeric)
$otp = Otp::for($user->email)->setExpiry(20)->generate();

Note: Default expiry is 10 minutes and you can change this to add the OTP_EXPIRY=20 in .env or config/otp.php file

License

统计信息

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

GitHub 信息

  • Stars: 18
  • Watchers: 0
  • Forks: 2
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2024-09-01

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固