-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAccount.java
More file actions
96 lines (73 loc) · 2.56 KB
/
Account.java
File metadata and controls
96 lines (73 loc) · 2.56 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
import java.io.Serializable;
import java.util.Calendar;
import java.util.GregorianCalendar;
import java.util.Date;
public class Account implements Serializable {
private static final long serialVersionUID = 1L;
private String name;
private String url;
private StandardPassword password;
public static void main(String[] args) {
// test class
Account acct = new Account("testAcct", "www.google.com", "testPassword1");
// should print "testPassword1"
System.out.println(acct.getPassword());
// should print "testAcct"
System.out.println(acct.getName());
// should print "www.google.com"
System.out.println(acct.getURL());
// test generatePassword
acct.generatePass(15);
System.out.println(acct.getPassword());
// set name to "testName" then print
acct.setName("testName");
System.out.println(acct.getName());
// set password to "testPass" then print
acct.setPassword("testPass");
System.out.println(acct.getPassword());
// set url to "www.test.com" then print
acct.setURL("www.test.com");
System.out.println(acct.getURL());
// test checkPassAge
acct.checkPassAge();
} // end main
public Account(String name, String url, String pass) {
this.name = name;
this.url = url;
this.password = new StandardPassword(pass);
} // end constructor
public void setName(String name) {
this.name = name;
} // end setName
public void setURL(String url) {
this.url = url;
} // end setURL
public void setPassword(String newPass) {
this.password.setPassword(newPass);
} // end setPassword
public String getName() {
return this.name;
} // end getName
public String getURL() {
return this.url;
} // end getURL
public String getPassword() {
return this.password.getPassword();
} // end getPassword
public void generatePass(int length) {
this.password.generatePass(length);
} // end generatePass
public void checkPassAge() {
Calendar dateSet = new GregorianCalendar();
dateSet.setTime(this.password.getDate());
Calendar today = new GregorianCalendar();
today.setTime(new Date());
int yearsDiff = today.get(Calendar.YEAR) - dateSet.get(Calendar.YEAR);
int monthsDiff = today.get(Calendar.MONTH) - dateSet.get(Calendar.MONTH);
long diffInMonths = yearsDiff * 12 + monthsDiff;
if (diffInMonths >= 6) {
System.out.println("The password for " + this.name + " is over 6 months old");
System.out.println("It is recommended to change your password every 6 months");
} // end if
} // end checkPassAge
} // end class