Download the PHP package codewiser/otp-authenticate without Composer
On this page you can find all versions of the php package codewiser/otp-authenticate. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download codewiser/otp-authenticate
More information about codewiser/otp-authenticate
Files in codewiser/otp-authenticate
Package otp-authenticate
Short Description One time passwords for Laravel
License MIT
Informations about the package otp-authenticate
One time passwords for Laravel
In a very simple case, our Laravel applications authenticates users by login and password. Sometimes we force our applications to verify user's emails.
This package requires users to periodically re-verify emails using one time passwords.
The authentication process will be:
- user signs-in with login and password
- application sends an email with one time password
- user affirms authentication providing this password
Installation
Install service.
Service Provider
Configure the frequency of email re-verification and rate limiters in a service provider class.
Providers/OtpServiceProvider.php
As you can see, we use extended OtpLimit with custom response that returns
user back to the previous page with a throttle message.
You may use base Limit as well.
Otp service constructor
OtpService class constructor has one optional parameter. It is a string in
date interval
format.
For example, if we define new OtpService('P1M'), users will sign in
using otp at least once a month.
Empty constructor new OtpService() means that every authentication process
accompanied by otp.
Either way, the otp process will be invoked no more often than once during user session.
Otp user contract
Apply MustVerifyEmailWithOtp contract and MustVerifyEmailWithOtp trait
to a User model. These contract and trait extends well known
MustVerifyEmail.
Models/User.php
Protecting routes
Use EnsureOtpIsPassed middleware to protect only stateful (web) requests.
To protect stateless (api) requests keep using
EnsureEmailIsVerified (aka verified) middleware.
routes/web.php
Customization
You may change published blade template, or you may register custom view. You may register custom function to generate otp codes. And you may register custom function for composing a notification.