Package rife.tools
Class TOTPUtils
java.lang.Object
rife.tools.TOTPUtils
Utility class providing the necessary functions to build 2FA using a time-based OTP algorithm
- Since:
- 1.0
-
Method Summary
Modifier and TypeMethodDescriptionstatic String
Generates a random secretstatic String
Generates the time-based code based on the given secretstatic String
Generates a Google Authenticator-compatible URL Formatting based on the document found here Can be used for QR-code image scanningstatic boolean
validateCode
(String secret, String inputCode) Code validation with a default of 1-step back, granting a 30-60 second windowstatic boolean
validateCode
(String secret, String inputCode, int stepsBack) Code validation where steps back can be customized to allow looser time-based authentication
-
Method Details
-
generateSecret
Generates a random secret- Returns:
- secret as a UTF-8 encoded
String
- Since:
- 1.0
-
getCode
Generates the time-based code based on the given secret- Parameters:
secret
- should be the UTF-8 encoded secret- Returns:
- time-based code as a
String
to use for authentication ornull
if secret is null or an empty string - Since:
- 1.0
-
validateCode
Code validation with a default of 1-step back, granting a 30-60 second window- Parameters:
secret
- should be the UTF-8 encoded secretinputCode
- should be the code input by the challenger- Returns:
true
if inputCode is valid,false
if invalid or if secret or inputCode are null- Since:
- 1.0
-
validateCode
Code validation where steps back can be customized to allow looser time-based authentication- Parameters:
secret
- should be the UTF-8 encoded secretinputCode
- should be the code input by the challengerstepsBack
- number of steps (30 second increments) to look back during authentication- Returns:
true
if inputCode is valid, @{code false} if invalid or if secret or inputCode are null- Since:
- 1.0
-
getUrl
Generates a Google Authenticator-compatible URL Formatting based on the document found here Can be used for QR-code image scanning- Parameters:
secret
- should be the UTF-8 encoded secretissuer
- should represent the account associated with the authenticationuser
- represents the user associated with the authentication- Returns:
- the URL to be used as a
String
- Since:
- 1.0
-