Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class Jaydev
- {
- public static void main(String[] args)
- {
- //Email list
- String[] emails = {"jaydev@test.com", "ryan@test.com", "ammar@test.com"};
- //password list
- String[] passwords = {"12345", "password", "qwerty"};
- //user input processor
- Scanner userInput = new Scanner(System.in);
- //get email ud use ur text field shit
- System.out.println("Enter email:");
- String emailToCheck = userInput.next();
- //need a flag to check if the email was found
- boolean emailFound = false;
- //Store the index of the email so u can just chek the password for that index. otherwise you could use your email and someone elses password
- int indexEmailFound = 0;
- //temp counter
- int temp = 0;
- //This just loops through the array and makes i the item that it is currently on in the array
- for (String i : emails)
- {
- //checks the user input against the current email in the loop
- if (emailToCheck.equals(i))
- {
- //if found make flag true and set the index to temp since u need it for password checking
- emailFound = true;
- indexEmailFound = temp;
- System.out.println("email found");
- }
- temp++;
- }
- //if the emails found do the password logic
- if (emailFound)
- {
- //get the password - u'd use ur field
- System.out.println("Enter Password");
- String passToCheck = userInput.next();
- //Check the password inputed to the password with the index in the passwords array
- // this makes sure the right email is to the right password
- if (passToCheck.equals(passwords[indexEmailFound]))
- {
- System.out.println("Password found");
- }
- //not found say it wasnt
- else
- {
- System.out.println("invalid password");
- }
- }
- //not found say it wasnt, can be a simple "error incorrect combo if you dont want the user to know if the email and password wasnt correct.
- else
- {
- System.out.println("invalid email");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement