daily pastebin goal
38%
SHARE
TWEET

Untitled

a guest Jul 21st, 2017 59 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import java.io.*;
  2.  
  3. public class LoginBot
  4. {
  5.     public LoginBot()
  6.     {
  7.     }
  8.     public LoginBot(String a, String b)
  9.     {
  10.         username = a;
  11.         password = b;
  12.         loggedIn = false;
  13.     }
  14.     public LoginBot(String a, String b, File f)
  15.     {
  16.         username = a;
  17.         password = b;
  18.         file = f;
  19.         loggedIn = false;
  20.     }
  21.    
  22.     public void login()
  23.     {
  24.         String path = "users/" + username + ".txt";
  25.  
  26.         if (!file.exists())
  27.         {
  28.             loggedIn = false;
  29.             System.out.println("\nError: invalid username/password.");
  30.         }
  31.         else
  32.         {
  33.             try
  34.             {
  35.                 fstream = new FileInputStream(path);
  36.                 dstream = new DataInputStream(fstream);
  37.                 br = new BufferedReader(new InputStreamReader(dstream));
  38.                 String inputLine;
  39.  
  40.                 while ((inputLine = br.readLine()) != null)
  41.                 {
  42.                     if (file.exists() && inputLine.equals(password))
  43.                     {
  44.                         loggedIn = true;
  45.                         System.out.println("\nThank you for logging in.");
  46.                     }
  47.                     else
  48.                     {
  49.                         loggedIn = false;
  50.                         System.out.println("\nError: invalid username/password.");
  51.                     }
  52.                 }
  53.             }
  54.             catch (IOException e)
  55.             {
  56.                 System.out.println("> There was an error while logging in.");
  57.             }
  58.         }
  59.     }
  60.  
  61.     public void createAccount()
  62.     {
  63.         System.out.println("\n> Creating account...");
  64.         String path = "users/" + username + ".txt";
  65.  
  66.         try
  67.         {
  68.             bw = new BufferedWriter(new FileWriter(path, true));
  69.             bw.write(password);
  70.             bw.close();
  71.             file = new File(path);
  72.             System.out.println("> Done!");
  73.         }
  74.         catch (IOException e)
  75.         {
  76.             System.out.println("> There was an error in creating your account.");
  77.         }
  78.     }
  79.  
  80.     public boolean isLoggedIn()
  81.     {
  82.         return loggedIn;
  83.     }
  84.     public void setParameters(String a, String b, File f)
  85.     {
  86.         username = a;
  87.         password = b;
  88.         file = f;
  89.     }
  90.     public void setUsername(String a)
  91.     {
  92.         username = a;
  93.     }
  94.     public void setPassword(String b)
  95.     {
  96.         password = b;
  97.     }
  98.     public void setFile(File f)
  99.     {
  100.         file = f;
  101.     }
  102.    
  103.     private String username;
  104.     private String password;
  105.     private File file;
  106.  
  107.     private boolean loggedIn;
  108.  
  109.     private FileInputStream fstream;
  110.     private DataInputStream dstream;
  111.         private BufferedReader br;
  112.     private BufferedWriter bw;
  113. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top