Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: time defaults #2

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/crystal-two-factor-auth.cr
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class TOTP
# * window_millis: Number of milliseconds that they are allowed to be off and still match. This checks before and after the current time to account for clock variance. Set to 0 for no window. Defaults to 10 seconds
# * time_millis: Time in milliseconds.
# * time_step_seconds: Time step in seconds. The default value is 30 seconds here
def self.validate_number_string(base32_secret : String, auth_number : String, window_millis : Int32 = 10000, time_millis : Int64 = Time.now.epoch_ms, time_step_seconds : Int32 = DEFAULT_TIME_STEP_SECONDS)
def self.validate_number_string(base32_secret : String, auth_number : String, window_millis : Int32 = 10000, time_millis : Int64 = Time.utc.to_unix_ms, time_step_seconds : Int32 = DEFAULT_TIME_STEP_SECONDS)
return false if base32_secret.empty? || auth_number.empty?
from = time_millis
to = time_millis
Expand All @@ -57,7 +57,7 @@ class TOTP
# Generate the authenticator number that is shown in the users app e.g. Google authenticator or Authy
# By default returns the current number but a time and time step can also be supplied.
# The returned number is zero padded if required.
def self.generate_number_string(base32_secret : String, time_millis : Int64 = Time.now.to_unix_ms, time_step_seconds : Int32 = DEFAULT_TIME_STEP_SECONDS)
def self.generate_number_string(base32_secret : String, time_millis : Int64 = Time.utc.to_unix_ms, time_step_seconds : Int32 = DEFAULT_TIME_STEP_SECONDS)
number = generate_number(base32_secret, time_millis, time_step_seconds)
"%06d" % number
end
Expand Down