Advertisement
Guest User

Untitled

a guest
Jun 13th, 2017
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.37 KB | None | 0 0
  1. import java.io.BufferedReader;
  2. import java.io.BufferedWriter;
  3. import java.io.File;
  4. import java.io.FileReader;
  5. import java.io.FileWriter;
  6. import java.io.IOException;
  7. import java.util.Scanner;
  8.  
  9. public class settings {
  10.    
  11.     void writeSettings() throws IOException {
  12.        
  13.         String key, username, password, autologin;
  14.        
  15.         Scanner scan = new Scanner(System.in);
  16.         File settings = new File("settings.txt");
  17.         boolean exists = settings.exists();
  18.  
  19.         if (!exists) {
  20.            
  21.             FileWriter fw = new FileWriter(settings);
  22.             BufferedWriter bw = new BufferedWriter(fw);
  23.            
  24.             System.out.println("It looks like this is your first time launching the client.");
  25.             System.out.print("Please enter your key: ");
  26.             key = scan.nextLine();
  27.             System.out.print("Username: ");
  28.             username = scan.nextLine();
  29.             System.out.print("Password: ");
  30.             password = scan.nextLine();
  31.             System.out.print("Would you like to enable autologin? (y/n): ");
  32.             autologin = scan.nextLine();
  33.            
  34.             bw.write(key);
  35.             bw.newLine();
  36.             bw.write(username);
  37.             bw.newLine();
  38.             bw.write(password);
  39.             bw.newLine();
  40.             bw.write(autologin);
  41.             bw.close();
  42.            
  43.             readSettings();
  44.            
  45.         }
  46.        
  47.         else if(exists) {
  48.            
  49.             readSettings();
  50.            
  51.         }
  52.        
  53.     }
  54.    
  55.     void readSettings() throws IOException {
  56.        
  57.         String keyRead, usernameRead, passwordRead, autologinRead;
  58.        
  59.         BufferedReader read = new BufferedReader(new FileReader("settings.txt"));
  60.        
  61.         keyRead = read.readLine();
  62.        
  63.         usernameRead = keyRead;
  64.        
  65.         while (usernameRead.equals(keyRead) && usernameRead != null) {
  66.            
  67.             usernameRead = read.readLine();
  68.            
  69.         }
  70.        
  71.         passwordRead = usernameRead;
  72.        
  73.         while (passwordRead.equals(usernameRead) && !passwordRead.equals(keyRead) && passwordRead != null) {
  74.            
  75.             passwordRead = read.readLine();
  76.            
  77.         }
  78.        
  79.         autologinRead = passwordRead;
  80.        
  81.         while (autologinRead.equals(passwordRead) && !autologinRead.equals(usernameRead) && autologinRead != null) {
  82.            
  83.         autologinRead = read.readLine();
  84.        
  85.         }
  86.        
  87.        
  88.         if (!keyRead.equals("153344985")) {
  89.            
  90.             System.out.println("Invalid key");
  91.            
  92.         }
  93.        
  94.         String logins[][] = {{"valon", "jamie", "admin"},
  95.                             {"leet", "leet", "supercool"}};
  96.  
  97.         if (autologinRead.equals("y")) {
  98.            
  99.             if ((usernameRead.equals(logins[0][0]) && passwordRead.equals(logins[1][0]))||
  100.                 (usernameRead.equals(logins[0][1]) && passwordRead.equals(logins[1][1]))||
  101.                 (usernameRead.equals(logins[0][2]) && passwordRead.equals(logins[1][2]))) {
  102.                
  103.                 System.out.println("Welcome " + usernameRead);
  104.                
  105.             }
  106.            
  107.             else {
  108.                
  109.                 System.out.println("Invalid username or password.");
  110.                
  111.             }
  112.         }
  113.        
  114.         else if(autologinRead.equals("n")) {
  115.            
  116.             String username, password;
  117.            
  118.             Scanner scan = new Scanner(System.in);
  119.            
  120.             System.out.print("Username: ");
  121.             username = scan.nextLine();
  122.             System.out.print("Password: ");
  123.             password = scan.nextLine();
  124.                
  125.                 if ((username.equals(logins[0][0]) && password.equals(logins[1][0]))||
  126.                     (username.equals(logins[0][1]) && password.equals(logins[1][1]))||
  127.                     (username.equals(logins[0][2]) && password.equals(logins[1][2]))) {
  128.                    
  129.                     System.out.println("Welcome "  + username);
  130.                    
  131.                 }
  132.                
  133.                 else {
  134.                    
  135.                     System.out.println("Invalid username or password.");
  136.                    
  137.                 }
  138.            
  139.         }
  140.        
  141.         else {
  142.            
  143.             System.out.println("Invalid username or password.");
  144.            
  145.         }
  146.     }
  147. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement