Advertisement
Guest User

login

a guest
Apr 5th, 2016
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.21 KB | None | 0 0
  1. package login;
  2.  
  3. import java.io.BufferedReader;
  4. import java.io.File;
  5. import java.io.FileReader;
  6. import java.io.IOException;
  7. import java.util.Scanner;
  8.  
  9. public class LoginMain {
  10.  
  11.     public static void main(String[] args) {
  12.         // TODO Auto-generated method stub
  13.        
  14.         Scanner scanner = new Scanner(System.in);
  15.        
  16.         System.out.println("Unesite korisnicko ime: ");
  17.         String korisnickoIme = scanner.nextLine();
  18.        
  19.         System.out.println("Unesite sifru: ");
  20.         String sifra = scanner.nextLine();
  21.        
  22.         try{
  23.             File korisniciFile = new File("src/fajlovi/korisnici.txt");
  24.             BufferedReader reader = new BufferedReader(new FileReader(korisniciFile));
  25.            
  26.             String line;
  27.             boolean loginOk = false;
  28.             while((line = reader.readLine()) != null){
  29.                 String[] lineSplit = line.split("\\|");
  30.                 String username = lineSplit[2];
  31.                 String password = lineSplit[3];
  32.                
  33.                 if(username.equalsIgnoreCase(korisnickoIme) && password.equals(sifra)){
  34.                     System.out.println("Uspesno ste se prijavili");
  35.                     loginOk = true;
  36.                     break;
  37.                 }
  38.             }
  39.             if(!loginOk){
  40.                 System.out.println("Login podaci nisu ispravni");
  41.             }
  42.             }catch(IOException e) {
  43.                 e.printStackTrace();
  44.                
  45.             }
  46.        
  47.         scanner.close();
  48.        
  49.        
  50.     }
  51.  
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement