0% found this document useful (0 votes)
3 views

Program

The document presents a Java program for a simple login system that uses a HashMap to store user credentials. It includes methods for validating user input and simulating user interaction through the console. The program continuously prompts for username and password until valid credentials are provided, after which it confirms a successful login.

Uploaded by

okchuzii12
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

Program

The document presents a Java program for a simple login system that uses a HashMap to store user credentials. It includes methods for validating user input and simulating user interaction through the console. The program continuously prompts for username and password until valid credentials are provided, after which it confirms a successful login.

Uploaded by

okchuzii12
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 1

import java.util.

HashMap;
import java.util.Map;
import java.util.Scanner;

public class LoginSystem {


private Map<String, String> usersDatabase = new HashMap<>();

// Constructor
public LoginSystem() {
// Adding some users to the system
usersDatabase.put("user1", "pass1");
usersDatabase.put("user2", "pass2");
}

// Method to validate credentials


public boolean validateCredentials(String username, String password) {
return usersDatabase.containsKey(username) &&
usersDatabase.get(username).equals(password);
}

// Main method to simulate user interaction


public static void main(String[] args) {
LoginSystem loginSystem = new LoginSystem();
Scanner scanner = new Scanner(System.in);

// Start
System.out.println("Welcome to the login system.");

while (true) {
// User input
System.out.print("Enter username: ");
String username = scanner.nextLine();
System.out.print("Enter password: ");
String password = scanner.nextLine();

// Validate credentials
if (loginSystem.validateCredentials(username, password)) {
System.out.println("Login successful! Welcome, " + username + ".");
// Simulate dashboard interaction
System.out.println("Performing operations...");
// End
break;
} else {
System.out.println("Invalid credentials. Please try again.");
}
}

scanner.close();
}
}

You might also like