The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.

NAME

Mslm::OTP - Perl module for handling OTP (One-Time Password) functionality

SYNOPSIS

  use Mslm::OTP;

  my $otp = Mslm::OTP->new($api_key);

  # Sending OTP
  my $response = $otp->send({
      phone          => '03001234567',
      tmpl_sms       => 'Your verification code is: <otp>',
      token_len      => 6,
      expire_seconds => 60
  });

  # Verifying OTP token
  my $verification_result = $otp->verify({
      phone   => '1234567890',
      token   => '123456',
      consume => \1
  });

DESCRIPTION

The Mslm::OTP module provides methods to send OTP (One-Time Password) and verify the OTP token using an API.

METHODS

new

Creates a new instance of Mslm::OTP.

Arguments

  • $api_key (string) - The API key required for authentication.

  • %opts (hash) - Optional parameters. You can pass in the following opts: base_url, user_agent, api_key, and http_client. These settings can also be done via the setter functions named: set_base_url, set_user_agent, set_api_key, set_http_client.

error_msg

Returns a string containing the error message of the last operation, it returns an empty string if the last operation was successful

set_base_url

Sets the base URL for API requests.

Arguments

  • $base_url_str (string) - The base URL to be set for API requests.

set_http_client

Sets the HTTP client for making requests.

Arguments

  • $http_client (LWP::UserAgent) - The HTTP client to be set.

set_user_agent

Sets the user agent for API requests.

Arguments

  • $user_agent (string) - The user agent string to be set.

set_api_key

Sets the API key for authentication.

Arguments

  • $api_key (string) - The API key to be set.

send

Sends an OTP to the specified phone number.

Arguments

  • $otp_send_req (hash reference) - A hash reference containing the OTP sending request parameters.

  • %opts (hash) - Optional parameters. You can pass in the following opts: base_url, user_agent, api_key, and http_client. These options will only work for the current request.

verify

Verifies the OTP token.

Arguments

  • $otp_token_verify_req (hash reference) - A hash reference containing the OTP token verification request parameters.

  • %opts (hash) - Optional parameters. You can pass in the following opts: base_url, user_agent, api_key, and http_client. These options will only work for the current request.

AUTHOR

Mslm, <usama.liaqat@mslm.io>

COPYRIGHT AND LICENSE

Copyright (c) 2022-now mslm. All rights reserved.