shared link 2fa
This commit is contained in:
committed by
Pete Matsyburka
parent
931addedbe
commit
a61c3e798d
@@ -0,0 +1,27 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
module EmailVerificationCodes
|
||||
DRIFT_BEHIND = 5.minutes
|
||||
|
||||
module_function
|
||||
|
||||
def generate(value)
|
||||
totp = ROTP::TOTP.new(build_totp_secret(value))
|
||||
|
||||
totp.at(Time.current)
|
||||
end
|
||||
|
||||
def verify(code, value)
|
||||
totp = ROTP::TOTP.new(build_totp_secret(value))
|
||||
|
||||
totp.verify(code, drift_behind: DRIFT_BEHIND)
|
||||
end
|
||||
|
||||
def build_totp_secret(value)
|
||||
ROTP::Base32.encode(
|
||||
Digest::SHA1.digest(
|
||||
[Rails.application.secret_key_base, value].join(':')
|
||||
)
|
||||
)
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user