Advertisement
Guest User

Untitled

a guest
Mar 23rd, 2019
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.94 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class Jaydev
  4. {
  5.     public static void main(String[] args)
  6.     {
  7.         //Email list
  8.         String[] emails = {"jaydev@test.com", "ryan@test.com", "ammar@test.com"};
  9.         //password list
  10.         String[] passwords = {"12345", "password", "qwerty"};
  11.        
  12.         //user input processor
  13.         Scanner userInput = new Scanner(System.in);
  14.         //get email ud use ur text field shit
  15.         System.out.println("Enter email:");
  16.         String emailToCheck = userInput.next();
  17.        
  18.         //need a flag to check if the email was found
  19.         boolean emailFound = false;
  20.         //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
  21.         int indexEmailFound = 0;
  22.        
  23.         //temp counter
  24.         int temp = 0;
  25.         //This just loops through the array and makes i the item that it is currently on in the array
  26.         for (String i : emails)
  27.         {
  28.             //checks the user input against the current email in the loop
  29.             if (emailToCheck.equals(i))
  30.             {
  31.                 //if found make flag true and set the index to temp since u need it for password checking
  32.                 emailFound = true;
  33.                 indexEmailFound = temp;
  34.                 System.out.println("email found");
  35.             }
  36.             temp++;
  37.         }
  38.        
  39.         //if the emails found do the password logic
  40.         if (emailFound)
  41.         {
  42.             //get the password - u'd use ur field
  43.             System.out.println("Enter Password");
  44.             String passToCheck = userInput.next();
  45.            
  46.             //Check the password inputed to the password with the index in the passwords array
  47.             // this makes sure the right email is to the right password
  48.             if (passToCheck.equals(passwords[indexEmailFound]))
  49.             {
  50.                 System.out.println("Password found");
  51.             }
  52.             //not found say it wasnt
  53.             else
  54.             {
  55.                 System.out.println("invalid password");
  56.             }
  57.         }
  58.         //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.
  59.         else
  60.         {
  61.             System.out.println("invalid email");
  62.         }
  63.     }
  64. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement