Advertisement
Guest User

Untitled

a guest
Apr 28th, 2017
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.52 KB | None | 0 0
  1. private void updateCreds() {
  2. String userResponse;
  3.  
  4. String username;
  5.  
  6. boolean pass = false;
  7. boolean email = true;
  8. CSVReader reader = null;
  9. if (currentUsername != "") {
  10. try {
  11. reader = new CSVReader(new FileReader("bin/creds.csv"), ',');
  12. List<String[]> csvBody = reader.readAll();
  13. updater = new Scanner(System.in);
  14.  
  15. while (true) {
  16. System.out.println("What would you like to update, Password or Email?");
  17. userResponse = updater.next();
  18. userResponse = toTitleCase(userResponse);
  19. if (userResponse.equals("Password")) {
  20. pass = true;
  21. break;
  22. } else if (userResponse.equals("Email")) {
  23. email = true;
  24. break;
  25. } else {
  26. System.out.println("Invalid Response");
  27. }
  28. }
  29. System.out.println("Current Username: " + currentUsername);
  30. for (String[] creds : csvBody) {
  31. if (currentUsername.equals(creds[1])) {
  32. if (pass) {
  33. System.out.println("Changing Password here");
  34. creds[2] = newPassword();
  35. } else if (email) {
  36. System.out.println("Changing Email here");
  37. creds[3] = newEmail();
  38. }
  39. }
  40. }
  41.  
  42.  
  43.  
  44. CSVWriter writer = new CSVWriter(new FileWriter("bin/creds.csv"), ',', CSVWriter.NO_QUOTE_CHARACTER);
  45. writer.writeAll(csvBody);
  46. writer.flush();
  47.  
  48.  
  49. } catch (FileNotFoundException e) {
  50. e.printStackTrace();
  51. } catch (IOException e) {
  52. e.printStackTrace();
  53. }
  54. }
  55. else{
  56. System.out.println("Verify you are logged in first!");
  57. }
  58. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement