Package util

Class OTPUtil

java.lang.Object
util.OTPUtil

public class OTPUtil extends Object
Utility class for generating and verifying time-based OTPs Uses current time as seed for synchronized OTP generation
Author:
TAMIL MUGHILAN
  • Constructor Details

    • OTPUtil

      public OTPUtil()
  • Method Details

    • generateOTP

      public static String 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

      public static boolean verifyOTP(String enteredOTP)
      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

      public static String generateOTPWithSeed(long seed)
      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