Advertisement
Guest User

Untitled

a guest
May 10th, 2019
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.95 KB | None | 0 0
  1. private void jButtonRegisterActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonRegisterActionPerformed
  2. // TODO add your handling code here:
  3. String firstName = jTextFirstName.getText();
  4. String lastName = jTextLastName.getText();
  5. String username = jTextUsername.getText();
  6. String password = new String(jPassword.getPassword());
  7. try{
  8. BufferedReader reader = new BufferedReader(new FileReader("/Users/pantvad/Downloads/Security_Project3/src/main/java/users.txt"));
  9. boolean check = false;
  10. for(String line;(line = reader.readLine()) != null;) {
  11. int i = line.indexOf('-');
  12. String testString = line.substring(0, i);
  13. if (testString.equals(username)) {
  14. check = true;
  15. break;
  16. }
  17. }
  18. if(!check) {
  19. StringBuilder usersInfo = new StringBuilder(username);
  20. usersInfo.append("-");
  21. usersInfo.append(firstName);
  22. usersInfo.append("-");
  23. usersInfo.append(lastName);
  24. usersInfo.append("-");
  25. usersInfo.append(password.hashCode());
  26. String last = usersInfo.toString();
  27. System.out.println(last);
  28. PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter("/Users/pantvad/Downloads/Security_Project3/src/main/java/users.txt", true)));
  29. out.println(last);
  30. out.close();
  31.  
  32. JOptionPane.showMessageDialog(new JFrame(), "Register Successfull");
  33. }
  34. else{
  35. JOptionPane.showMessageDialog(new JFrame(), "Username already exists");
  36. }
  37. } catch (IOException e) {
  38. e.printStackTrace();
  39. }
  40. //System.out.println(firstName + lastName + username + password);
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement