Package com.webarity.auth
Enum TimeOneTimePassword
- java.lang.Object
-
- java.lang.Enum<TimeOneTimePassword>
-
- com.webarity.auth.TimeOneTimePassword
-
- All Implemented Interfaces:
java.io.Serializable
,java.lang.Comparable<TimeOneTimePassword>
public enum TimeOneTimePassword extends java.lang.Enum<TimeOneTimePassword>
Defaults:
- TIME_STEP = 30
- START_TIME = 0
- PIN_LENGTH = 6
- See Also:
- Google Authenticator
-
-
Enum Constant Summary
Enum Constants Enum Constant Description HMACSHA1
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description java.lang.String
oneTimePassword(java.lang.String secret)
Uses the defaults for ping length, start time, time step.java.lang.String
oneTimePassword(java.lang.String secret, int pinLength)
java.lang.String
oneTimePassword(java.lang.String secret, long startTime, long timeStep, int pinLength)
java.lang.String
oneTimePassword(java.lang.String secret, long nowTime, long startTime, long timeStep, int pinLength)
Control over all attributes.static TimeOneTimePassword
valueOf(java.lang.String name)
Returns the enum constant of this type with the specified name.static TimeOneTimePassword[]
values()
Returns an array containing the constants of this enum type, in the order they are declared.
-
-
-
Enum Constant Detail
-
HMACSHA1
public static final TimeOneTimePassword HMACSHA1
-
-
Method Detail
-
values
public static TimeOneTimePassword[] values()
Returns an array containing the constants of this enum type, in the order they are declared. This method may be used to iterate over the constants as follows:for (TimeOneTimePassword c : TimeOneTimePassword.values()) System.out.println(c);
- Returns:
- an array containing the constants of this enum type, in the order they are declared
-
valueOf
public static TimeOneTimePassword valueOf(java.lang.String name)
Returns the enum constant of this type with the specified name. The string must match exactly an identifier used to declare an enum constant in this type. (Extraneous whitespace characters are not permitted.)- Parameters:
name
- the name of the enum constant to be returned.- Returns:
- the enum constant with the specified name
- Throws:
java.lang.IllegalArgumentException
- if this enum type has no constant with the specified namejava.lang.NullPointerException
- if the argument is null
-
oneTimePassword
public java.lang.String oneTimePassword(java.lang.String secret) throws java.lang.Exception
Uses the defaults for ping length, start time, time step. Uses
System.currentTimeMillis() / 1000
to get he right-now-time- Parameters:
secret
- shared secret between Google Authenticator and Server- Returns:
- a 6 digit pin, computed for current step of 30 seconds and start time 0
- Throws:
java.lang.Exception
- catch-all Exception related tocomputePin
orByteBuffer
-
oneTimePassword
public java.lang.String oneTimePassword(java.lang.String secret, int pinLength) throws java.lang.Exception
- Parameters:
secret
- shared secret between Google Authenticator and ServerpinLength
- length of the pin/password- Returns:
- the pin with the specified length, computed for current step of 30 seconds and start time 0
- Throws:
java.lang.Exception
- catch-all Exception related tocomputePin
orByteBuffer
-
oneTimePassword
public java.lang.String oneTimePassword(java.lang.String secret, long startTime, long timeStep, int pinLength) throws java.lang.Exception
- Parameters:
secret
- shared secret between Google Authenticator and ServerstartTime
- unix time to start counting time steps, usually it will be 0, see README.mdtimeStep
- window between new code generation, in secondspinLength
- length of the pin/password- Returns:
- the pin with the specified length, computed for current step of 30 seconds and start time 0
- Throws:
java.lang.Exception
- catch-all Exception related tocomputePin
orByteBuffer
-
oneTimePassword
public java.lang.String oneTimePassword(java.lang.String secret, long nowTime, long startTime, long timeStep, int pinLength) throws java.lang.Exception
Control over all attributes. May use the
nowTime
for calculating older values in order to account for network delays or slow entry on demand, without actually storing those values to begin with.- Parameters:
secret
- shared secret between Google Authenticator and ServernowTime
- the right now time in Unix; expects seconds, should be in seconds - for ex.,System.currentTimeMillis() / 1000
startTime
- unix time to start counting time steps, usually it will be 0, see README.mdtimeStep
- window between new code generation, in secondspinLength
- length of the pin/password- Returns:
- the pin with the specified length, computed for current step of 30 seconds and start time 0
- Throws:
java.lang.Exception
- catch-all Exception related tocomputePin
orByteBuffer
-
-