Advertisement
Guest User

Untitled

a guest
Mar 31st, 2017
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.89 KB | None | 0 0
  1. ublic boolean passwordCheck() {
  2. if (!tPassword1.getText().equals(tPassword2.getText())) {
  3. JOptionPane.showMessageDialog(Signup.this, "Passwords do not match try again.", "Error",
  4. JOptionPane.ERROR_MESSAGE);
  5. return false;
  6.  
  7. }
  8. return true;
  9. }
  10.  
  11. private boolean readLogin() {
  12. try {
  13. BufferedReader getData = new BufferedReader(new FileReader(new File("UPW.txt")));
  14. String logininfo = getData.readLine();
  15.  
  16. while (logininfo != null) {
  17. String[] pass = logininfo.split(",");
  18. if (pass[0].equals(tUsername.getText())) {
  19.  
  20. JOptionPane.showMessageDialog(Signup.this, "Username is already taken. Please try again.", "Error",
  21. JOptionPane.ERROR_MESSAGE);
  22. return false;
  23. }
  24. logininfo = getData.readLine();
  25. }
  26. getData.close();
  27. } catch (IOException e) {
  28. System.out.println(e);
  29. System.exit(0);
  30. }
  31. return true;
  32. }
  33.  
  34. private class ListenForButton implements ActionListener {
  35. public void actionPerformed(ActionEvent d) {
  36. if (d.getSource() == signUp) {
  37.  
  38. if (readLogin() && passwordCheck()) {
  39. new writer(tUsername.getText(), tPassword1.getText(), tPassword2.getText());
  40. JOptionPane.showMessageDialog(Signup.this, "You have successfully signed up.", "",
  41. JOptionPane.PLAIN_MESSAGE);
  42. dispose();
  43.  
  44. }
  45.  
  46. } else if (d.getSource() == cancel) {
  47. dispose();
  48.  
  49. }
  50. }
  51. }
  52.  
  53. public class writer {
  54. private String username;
  55. private String password;
  56.  
  57. public writer(String username, String password, String confirm) {
  58. this.username = username;
  59. this.password = password;
  60.  
  61. try {
  62. PrintWriter fileOut = new PrintWriter(new BufferedWriter(new FileWriter("UPW.txt", true)));
  63. fileOut.println(this.username + "," + this.password);
  64. fileOut.close();
  65. } catch (IOException e) {
  66. System.out.println("could not find and/or open file");
  67. System.out.println(e);
  68. }
  69. }
  70. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement