OTPService
in package
Class OTPService
Provides services for handling OTP (One-Time Password) operations.
Table of Contents
Methods
- requestFor() : int
- Generates and stores a new OTP for the user.
- send() : bool
- Sends an OTP to the user's phone number via WhatsApp API.
- verify() : bool
- Verifies the provided OTP for the user.
Methods
requestFor()
Generates and stores a new OTP for the user.
public
requestFor(User $user[, int $expirationMinutes = 5 ]) : int
Parameters
- $user : User
-
The user for whom the OTP is generated.
- $expirationMinutes : int = 5
-
The expiration time of the OTP in minutes.
Return values
int —The generated OTP code.
send()
Sends an OTP to the user's phone number via WhatsApp API.
public
send(User $user, string $otp, string $phone[, int $expirationMinutes = 5 ]) : bool
Parameters
- $user : User
-
The user to whom the OTP is sent.
- $otp : string
-
The OTP code to send.
- $phone : string
-
The phone number to send the OTP to.
- $expirationMinutes : int = 5
-
The expiration time of the OTP in minutes.
Return values
bool —True if the OTP was sent successfully, false otherwise.
verify()
Verifies the provided OTP for the user.
public
verify(User $user, string $otp) : bool
Parameters
- $user : User
-
The user whose OTP is being verified.
- $otp : string
-
The OTP code to verify.
Return values
bool —True if the OTP is valid, false otherwise.