Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
4 views
in Java by (7k points)
I am a new programmer and I want to implement a simple login page for a project I am doing. Can someone help me with this?

1 Answer

0 votes
by (13.1k points)

You can try like this:

import java.util.Scanner;

public class Login {

public void run() {

    Scanner scan = new Scanner (new File("Filecontainingcredentials.extension"));

    Scanner userInput = new Scanner (System.in);

    String user = scan.nextLine();

    String pass = scan.nextLine(); 

    String inputUser = userInput.nextLine();

    String inputPass = userInput.nextLine();

    if (inputUser.equals(user) && inputPass.equals(pass)) {

        System.out.print("Login successful");

    } else {

        System.out.print("Login error");

    }

}

}

Beware of where you use it, it is not that secure, it just gives you an idea of how the login system works.

Want to learn Java? Check out the Java certification from Intellipaat.

Related questions

Browse Categories

...