CodeHub Menu
Home Exercise Practice About Download Portfolio Play Games NEW Privacy Policy Terms Contact
Login / Register

OTP BASED LOGIN SYSTEM IN JAVA

JAVA November 19, 2025 5 views 0 likes
Design a System in JAVA to do OTP Based Login System where user name and password is predifiend.

Answer:

otp - Java Code

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");
        }
    }
}

Output:

OTP Verification

Login & OTP Verification







5 views 0 likes
Total visits: 2,089 • Unique visitors: 1,285