Package util
Class OTPUtil
java.lang.Object
util.OTPUtil
Utility class for generating and verifying time-based OTPs
Uses current time as seed for synchronized OTP generation
- Author:
- TAMIL MUGHILAN
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic String
Generates a 6-digit OTP using current time as seed.static String
generateOTPWithSeed
(long seed) Generates OTP with custom seed for testing purposes.static boolean
Verifies if the entered OTP matches the expected OTP.
-
Constructor Details
-
OTPUtil
public OTPUtil()
-
-
Method Details
-
generateOTP
Generates a 6-digit OTP using current time as seed. Uses minutes to ensure same OTP within same minute.- Returns:
- 6-digit OTP as String
-
verifyOTP
Verifies if the entered OTP matches the expected OTP. Generates expected OTP using current time and compares.- Parameters:
enteredOTP
- the OTP entered by user- Returns:
- true if OTP is valid, false otherwise
-
generateOTPWithSeed
Generates OTP with custom seed for testing purposes. Useful for testing with known seeds.- Parameters:
seed
- custom seed for random number generation- Returns:
- 6-digit OTP as String
-