Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.*;
- public class LoginBot
- {
- public LoginBot()
- {
- }
- public LoginBot(String a, String b)
- {
- username = a;
- password = b;
- loggedIn = false;
- }
- public LoginBot(String a, String b, File f)
- {
- username = a;
- password = b;
- file = f;
- loggedIn = false;
- }
- public void login()
- {
- String path = "users/" + username + ".txt";
- if (!file.exists())
- {
- loggedIn = false;
- System.out.println("\nError: invalid username/password.");
- }
- else
- {
- try
- {
- fstream = new FileInputStream(path);
- dstream = new DataInputStream(fstream);
- br = new BufferedReader(new InputStreamReader(dstream));
- String inputLine;
- while ((inputLine = br.readLine()) != null)
- {
- if (file.exists() && inputLine.equals(password))
- {
- loggedIn = true;
- System.out.println("\nThank you for logging in.");
- }
- else
- {
- loggedIn = false;
- System.out.println("\nError: invalid username/password.");
- }
- }
- }
- catch (IOException e)
- {
- System.out.println("> There was an error while logging in.");
- }
- }
- }
- public void createAccount()
- {
- System.out.println("\n> Creating account...");
- String path = "users/" + username + ".txt";
- try
- {
- bw = new BufferedWriter(new FileWriter(path, true));
- bw.write(password);
- bw.close();
- file = new File(path);
- System.out.println("> Done!");
- }
- catch (IOException e)
- {
- System.out.println("> There was an error in creating your account.");
- }
- }
- public boolean isLoggedIn()
- {
- return loggedIn;
- }
- public void setParameters(String a, String b, File f)
- {
- username = a;
- password = b;
- file = f;
- }
- public void setUsername(String a)
- {
- username = a;
- }
- public void setPassword(String b)
- {
- password = b;
- }
- public void setFile(File f)
- {
- file = f;
- }
- private String username;
- private String password;
- private File file;
- private boolean loggedIn;
- private FileInputStream fstream;
- private DataInputStream dstream;
- private BufferedReader br;
- private BufferedWriter bw;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement