Send OTP (One Time Password)

A one-time password (OTP) is an automatically generated numeric or alphanumeric string of characters that authenticates the user for a single transaction or login session.

Sending OTP

Parameters

Descriptions

receiver_otp

Receiver number (e.g, [code country][number] 6283838204803)

message

This parameter's type data is callable, so you can custom your message OTP

function send(string $receiver_otp, callable $message = NULL)

This function has a default message

protected string $otp_message = 'Dear Customer, Your OTP is [otp]. Use this Passcode to complete your activity that needed the OTP code. Thank you.';

Example

\Ardzz\Wavel\Wavel::OTP()->send(receiver_otp: '6283838204803');
\Ardzz\Wavel\Wavel::OTP()->send(
    receiver_otp: '6283838204803',
    message: fn($OTPCode) => "Hello Ardhana, this is your OTP code {$OTPCode}"
);

Validating OTP

Parameters

Descriptions

receiver_otp

The receiver OTP marked as identifier to verify their OTP code (e.g, [code country][number] 6283838204803)

code

OTP Code that given to receiver_otp

function validate(string $receiver_otp, string|int $code)

Example

$validate = \Ardzz\Wavel\Wavel::OTP()->validate(
    receiver_otp: '6283838204803',
    code: '123456'
);

if($validate){
    echo 'OTP is valid';
}else{
    echo 'OTP is invalid';
}

Last updated

Was this helpful?