This is a Java Program to Illustrate how User Authentication is Done.
Enter username and password as input strings. After that we match both strings against given username and password. If it matches then Authentication is successfull or else Authentication fails.
Here is the source code of the Java Program to Illustrate how User Authentication is Done. The Java program is successfully compiled and run on a Windows system. The program output is also shown below.
import java.util.Scanner;
public class User_Authentication
{
public static void main(String args[])
{
String username, password;
Scanner s = new Scanner(System.in);
System.out.print("Enter username:");//username:user
username = s.nextLine();
System.out.print("Enter password:");//password:user
password = s.nextLine();
if(username.equals("user") && password.equals("user"))
{
System.out.println("Authentication Successful");
}
else
{
System.out.println("Authentication Failed");
}
}
}
Output:
$ javac User_Authentication.java $ java User_Authentication Enter username:user Enter password:user Authentication Successful Enter username:abcd Enter password:1234 Authentication Failed
Sanfoundry Global Education & Learning Series – 1000 Java Programs.
advertisement
advertisement
Here’s the list of Best Books in Java Programming, Data Structures and Algorithms.
If you find any mistake above, kindly email to [email protected]Related Posts:
- Apply for Java Internship
- Practice BCA MCQs
- Check Programming Books
- Apply for Computer Science Internship
- Practice Information Technology MCQs