module SmartSMS::VerificationCode

This module provides some methods to generate random verification code

Algorithm:

* short:    Generate short code with 4 numbers
* simple:   Generate simple code with 6 numbers
* middle:   Generate middle complex code of 6 charactors with mixed numbers and letters
* complex:  Generate complex code of 8 charactors with mixed numbers, letters or special charactors

Constants

REGISTERED_ALGORITHMS

Public Instance Methods

complex() click to toggle source
# File lib/smart_sms/helpers/verification_code.rb, line 38
def complex
  SecureRandom.base64.slice(1..8).downcase
end
middle() click to toggle source
# File lib/smart_sms/helpers/verification_code.rb, line 34
def middle
  SecureRandom.base64.gsub!(/[^0-9a-zA-Z]/, '').slice(1..6).downcase
end
random(algorithm = '') click to toggle source
# File lib/smart_sms/helpers/verification_code.rb, line 17
def random(algorithm = '')
  algorithm = SmartSMS.config.verification_code_algorithm if algorithm.blank?
  if REGISTERED_ALGORITHMS.include? algorithm
    SmartSMS::VerificationCode.send algorithm
  else
    fail NoMethodError
  end
end
short() click to toggle source
# File lib/smart_sms/helpers/verification_code.rb, line 26
def short
  SecureRandom.random_number.to_s.slice(-4..-1)
end
simple() click to toggle source
# File lib/smart_sms/helpers/verification_code.rb, line 30
def simple
  SecureRandom.random_number.to_s.slice(-6..-1)
end