Class: SecondFactor::HOTP

Inherits:
Object
  • Object
show all
Defined in:
lib/secondfactor/hotp.rb

Class Method Summary collapse

Class Method Details

.generate(secret_based, step) ⇒ Object



3
4
5
6
7
# File 'lib/secondfactor/hotp.rb', line 3

def self.generate(secret_based, step)
  hmac = SecondFactor::OTP.generate_hmac(secret_based, step)
  hotp = (hmac % 10 ** 6).to_s.rjust(6, '0')
  return hotp
end

.verify(secret_based, step, token) ⇒ Object



9
10
11
12
# File 'lib/secondfactor/hotp.rb', line 9

def self.verify(secret_based, step, token)
  challenge = self.generate(secret_based, step)
  return challenge == token
end