Otp Generator using LocalTime Library in java
CODE :
import java.util.*;
import java.time.*;
class Otpt{
public static void otp()
{
Scanner sc = new Scanner(System.in);
LocalTime t = LocalTime.now();
String time = t.toString();
String p = "";
for (int i = 1; i < time.length(); i += 2) {
p += String.valueOf((int) Math.pow(Character.getNumericValue(time.charAt(i)), 2));
}
String tm = p.substring(4,8);
System.out.println("Your Otp is : "+tm);
System.out.print("Please Enter Otp : ");
String totp = sc.next();
if(tm.equals(totp)){
System.out.println("Otp Verification Successfull");}
else{
System.out.println("The otp u've entered is invalid");
otp();
}
}
public static void main(String args[])
{ otp();
}
}
Inputs and Outputs :