/src/com/titanPlayer/bll/UserAccount.java

https://github.com/KyleGrice/MusicPlayerProject · Java · 70 lines · 47 code · 12 blank · 11 comment · 9 complexity · 7090cd1e80e32e69fc62c6573d038087 MD5 · raw file

  1. /*
  2. * To change this template, choose Tools | Templates
  3. * and open the template in the editor.
  4. */
  5. package com.titanPlayer.bll;
  6. import java.util.regex.Matcher;
  7. import java.util.regex.Pattern;
  8. /**
  9. *
  10. * @author Kyle
  11. */
  12. public class UserAccount {
  13. private String userName;
  14. private String password;
  15. private String email;
  16. public static final Pattern VALID_EMAIL_ADDRESS_REGEX =
  17. Pattern.compile("^[A-Z0-9._%+-]+@[A-Z0-9.-]+\\.[A-Z]{2,6}$", Pattern.CASE_INSENSITIVE);
  18. private String message = "";
  19. public UserAccount(String userName, String password, String email) {
  20. this.userName = userName;
  21. this.password = password;
  22. this.email = email;
  23. }
  24. public boolean ValidAccount() {
  25. boolean validAccount = false;
  26. int validEntries = 0;
  27. final int VALID_ENTRIES_REQUIRED = 3;
  28. // validate User Name
  29. if (!userName.equals("")) {
  30. validEntries++;
  31. }
  32. else {
  33. message += "User Name cannot be blank.\n";
  34. }
  35. // Validate Password
  36. if (password.matches("^(?=.*[0-9])(?=.*[a-zA-Z])(?=.*[!@#$%^&*_-]).+$") && !password.equals("")) {
  37. validEntries++;
  38. }
  39. else {
  40. message += "Password cannot be blank and must have at least one letter, one number, and one special character.\n";
  41. }
  42. // Validate Email
  43. Matcher matcher = VALID_EMAIL_ADDRESS_REGEX .matcher(email);
  44. if (matcher.find()) {
  45. validEntries++;
  46. }
  47. else {
  48. message += "Email must follow standard conventions.";
  49. }
  50. if (validEntries == VALID_ENTRIES_REQUIRED) {
  51. validAccount = true;
  52. }
  53. return validAccount;
  54. }
  55. public String InvalidMessage() {
  56. return message;
  57. }
  58. }