Class: SecondFactor::TOTP

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

Class Method Summary collapse

Class Method Details

.generate(secret_based) ⇒ Object



3
4
5
6
7
8
9
10
11
# File 'lib/secondfactor/totp.rb', line 3

def self.generate(secret_based)
  now_step = Time.now.to_i / 30

  return [
    SecondFactor::HOTP.generate(secret_based, now_step.pred),
    SecondFactor::HOTP.generate(secret_based, now_step),
    SecondFactor::HOTP.generate(secret_based, now_step.succ)
  ]
end

.verify(secret_based, token) ⇒ Object



13
14
15
16
# File 'lib/secondfactor/totp.rb', line 13

def self.verify(secret_based, token)
  challenges = self.generate(secret_based)
  return challenges.include? token
end