Design a System in JAVA to do OTP Based Login System where user name and password is predifiend.
otp - Java Code
OTP Verification
Answer:
otp - Java Code
import java.util.*;
public class otp
{
public static void main()
{
int otp = (int)((Math.random() * 100000) + 1);
System.out.println("Your OTP is: " + otp);
String user = "admin";
String pass = "admin";
Scanner ot = new Scanner(System.in);
System.out.println("Username: ");
String USER = ot.nextLine();
System.out.println("Password: ");
String PASS = ot.nextLine();
if (user.equals(USER) && pass.equals(PASS))
{
System.out.println("Enter the OTP: ");
int OTP = ot.nextInt();
if (otp == OTP)
{
System.out.println("Your Otp Verified Successfully");
}
else
{
System.out.println("Your Otp is Invalid");
}
}
else
{
System.out.println("Username Or Password is incorrect");
}
}
}