diff options
Diffstat (limited to 'internal/userutil')
-rw-r--r-- | internal/userutil/userutil.go | 10 | ||||
-rw-r--r-- | internal/userutil/userutil_test.go | 10 |
2 files changed, 20 insertions, 0 deletions
diff --git a/internal/userutil/userutil.go b/internal/userutil/userutil.go index d8a8b031..6d324ff6 100644 --- a/internal/userutil/userutil.go +++ b/internal/userutil/userutil.go @@ -122,3 +122,13 @@ func ValidatePassword(encoded, salt, password string) bool { got := EncodePassword(password, salt) return subtle.ConstantTimeCompare([]byte(encoded), []byte(got)) == 1 } + +// MailResendCacheKey returns the key used for caching mail resend. +func MailResendCacheKey(userID int64) string { + return fmt.Sprintf("mailResend::%d", userID) +} + +// TwoFactorCacheKey returns the key used for caching two factor passcode. +func TwoFactorCacheKey(userID int64, passcode string) string { + return fmt.Sprintf("twoFactor::%d::%s", userID, passcode) +} diff --git a/internal/userutil/userutil_test.go b/internal/userutil/userutil_test.go index 895f7e26..e46546bd 100644 --- a/internal/userutil/userutil_test.go +++ b/internal/userutil/userutil_test.go @@ -181,3 +181,13 @@ func TestValidatePassword(t *testing.T) { }) } } + +func TestMailResendCacheKey(t *testing.T) { + got := MailResendCacheKey(1) + assert.Equal(t, "mailResend::1", got) +} + +func TestTwoFactorCacheKey(t *testing.T) { + got := TwoFactorCacheKey(1, "113654") + assert.Equal(t, "twoFactor::1::113654", got) +} |