Class: Otp::Generate

Inherits:
Object
  • Object
show all
Defined in:
lib/otp/generate.rb

Overview

This class provides functionality to generate a One-Time Password (OTP). It generates a random numeric string of a specified length, which defaults to 6 digits.

Constant Summary collapse

OTP_LENGTH =
6

Class Method Summary collapse

Class Method Details

.callString

Generates a random OTP of the specified length.

Returns:

  • (String)

    A string representing the generated OTP, padded with leading zeros if necessary.



9
10
11
# File 'lib/otp/generate.rb', line 9

def self.call
  SecureRandom.random_number(10**OTP_LENGTH).to_s.rjust(OTP_LENGTH, "0")
end