Advertisement
YST

USER LOGIN

YST
Mar 18th, 2016
142
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.51 KB | None | 0 0
  1. //login class
  2. /**
  3.  * Created by yst on 11/03/2016.
  4.  */
  5. public class login {
  6.     private String username;
  7.     private String password;
  8.  
  9.     //default constructor
  10.     public login(){
  11.         username=" ";
  12.         password=" ";
  13.     }
  14.     //normal constructor
  15.     public login(String u,String p){
  16.         username=u;
  17.         password=p;
  18.     }
  19.     //getter
  20.     public String getUsername(){
  21.         return username;
  22.     }
  23.     public String getPassword(){
  24.         return password;
  25.     }
  26. }
  27. //main class
  28. /**
  29.  * Created by yst on 11/03/2016.
  30.  */
  31. import java.util.*;
  32. public class APP {
  33.     public static void main(String[] args){
  34.         String username=" ",password=" ";
  35.         Scanner input=new Scanner(System.in);
  36.         System.out.print("USERNAME :" );
  37.         username=input.next();
  38.         System.out.print("PASSWORD :");
  39.         password=input.next();
  40.  
  41.         //Arraylist for login
  42.         ArrayList<login> a =new ArrayList<login>();
  43.  
  44.         //adding object to a arraylist
  45.         a.add(new login("balqis","hanis"));
  46.         a.add(new login("safuan","alane"));
  47.         a.add(new login("abah","caah"));
  48.  
  49.         //username and password will be search according to the index respectively
  50.         for(int counter=0;counter<a.size();counter++){
  51.             if((a.get(counter).getUsername().equalsIgnoreCase(username))&&(a.get(counter).getPassword().equalsIgnoreCase(password))) {
  52.                 System.out.println("Sucessfully Login");
  53.                 break;
  54.             }
  55.         }
  56.     }
  57. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement