Guest User

Untitled

a guest
Jul 3rd, 2018
138
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.59 KB | None | 0 0
  1. public class SecondLifeAccount2 {
  2.  
  3. private String username;
  4. private String password;
  5. private int dob;
  6. private String secretQuestion;
  7. private String secretAnswer;
  8. static final String FILENAME = "SLAccountTest.txt";
  9.  
  10. /**
  11. * Create variables for SecondLifeAccount2 object.
  12. *
  13. * @param u user's desired username
  14. * @param p user's desired password
  15. * @param d user's date of birth
  16. * @param q user's secret question
  17. * @param a user's answer to secret question
  18. */
  19. public SecondLifeAccount2(String u, String p, int d,
  20. String q, String a) {
  21. username = u;
  22. password = p;
  23. dob = d;
  24. secretQuestion = q;
  25. secretAnswer = a;
  26.  
  27. }
  28.  
  29. /**
  30. * Check if username is appropriate number of characters.
  31. *
  32. * @param username User's entered username
  33. * @return true or false
  34. */
  35. public static boolean goodUsername(String username) {
  36. int minChars = 10;
  37. int maxChars = 20;
  38.  
  39. if (username.length() >= minChars && username.length() <= maxChars) {
  40. return true;
  41. } else {
  42. return false;
  43. }
  44. }
  45.  
  46. /**
  47. * Check if password is appropriate number of characters and if it meets
  48. * uppercase, lower case, and digit criteria.
  49. *
  50. * @param username User's entered password
  51. * @return true or false
  52. */
  53. public static boolean goodPassword(String password) {
  54. int pos = 0;
  55. int countU = 0;
  56. int countL = 0;
  57. int countD = 0;
  58. int minChars = 6;
  59. int maxChars = 16;
  60.  
  61. if (password.length() >= minChars && password.length() <= maxChars) {
  62. while (pos < password.length()) {
  63. char letter = password.charAt(pos);
  64. pos++;
  65. if (Character.isUpperCase(letter)) {
  66. countU++;
  67. }
  68. if (Character.isLowerCase(letter)) {
  69. countL++;
  70. }
  71. if (Character.isDigit(letter)) {
  72. countD++;
  73. }
  74. }
  75. if (password.length() >= minChars && password.length()
  76. <= maxChars && countU > 0 && countL > 0 && countD > 0) {
  77. return true;
  78. }
  79. }
  80. return false;
  81. }
  82.  
  83. /**
  84. * Check if date of birth is valid and that the birth year is 1900 or later.
  85. *
  86. * @param username User's entered date of birth
  87. * @return true or false
  88. */
  89. public static boolean goodDob(int dob) {
  90. int day, month, year, birthday = dob;
  91. year = birthday % 10000;
  92. birthday = birthday / 10000;
  93. day = birthday % 100;
  94. birthday = birthday / 100;
  95. month = birthday;
  96.  
  97. if (month <= 12 && month > 0 && day <= 31 && day > 0
  98. && year <= 1996 && year >= 1900) {
  99. return true;
  100. } else {
  101. return false;
  102. }
  103. }
  104.  
  105. /**
  106. * Retrieve username
  107. *
  108. * @return
  109. */
  110. public String getUsername() {
  111. return username;
  112. }
  113.  
  114. /**
  115. * Set user's username
  116. *
  117. * @param u User's desired username
  118. */
  119. public void setUsername(String u) {
  120. username = u;
  121. }
  122.  
  123. /**
  124. * Retrieve user's password
  125. *
  126. * @return
  127. */
  128. public String getPassword() {
  129. return password;
  130. }
  131.  
  132. /**
  133. * Set user's password
  134. *
  135. * @param p User's desired password
  136. */
  137. public void setPassword(String p) {
  138. password = p;
  139. }
  140.  
  141. /**
  142. * Retrieve user's date of birth
  143. *
  144. * @return
  145. */
  146. public int getDob() {
  147. return dob;
  148. }
  149.  
  150. /**
  151. * Set user's date of birth
  152. *
  153. * @param d User's date of birth
  154. */
  155. public void setDob(int d) {
  156. dob = d;
  157. }
  158.  
  159. /**
  160. * Retrieve user's secret question
  161. *
  162. * @return
  163. */
  164. public String getSecretQuestion() {
  165. return secretQuestion;
  166. }
  167.  
  168. /**
  169. * Set user's secret question
  170. *
  171. * @param q User's secret question
  172. */
  173. public void setSecretQuestion(String q) {
  174. secretQuestion = q;
  175. }
  176.  
  177. /**
  178. * Retrieve user's secret answer
  179. *
  180. * @return
  181. */
  182. public String getSecretAnswer() {
  183. return secretAnswer;
  184. }
  185.  
  186. /**
  187. * Set user's answer to secret question
  188. *
  189. * @param a User's answer to secret question
  190. */
  191. public void setSecretAnswer(String a) {
  192. secretAnswer = a;
  193. }
  194. }
Add Comment
Please, Sign In to add comment