mirror of
https://github.com/docusealco/docuseal
synced 2026-11-07 07:22:32 -05:00
shared link 2fa
This commit is contained in:
1 parent
931addedbe
commit
a61c3e798d
19 files changed
+479
-20
No files matched your search
@@ -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