Minor changes
[RRRRHHHH_Code] / ruralHouses / src / domain / Account.java
1 package domain;
2
3 import java.io.Serializable;
4 import java.util.Arrays;
5
6 import businessLogic.SecurityManager;
7
8 public class Account implements Serializable {
9
10         /**
11          * 
12          */
13         private static final long serialVersionUID = 1L;
14         
15
16         private byte[] username;
17         private byte[] password;
18         private byte[] salt;
19
20
21         private Owner owner;
22         private boolean admin = false;
23
24         
25         public Account(byte[] usr){
26                 this.username = usr;
27                 this.salt =null;
28                 this.password = null;
29                 this.owner = null;
30                 
31         }
32         public Account(Owner own){
33                 this.username = null;
34                 this.salt =null;
35                 this.password = null;
36                 this.owner = own;
37                 
38         }
39         public Account(String usr, String pass, boolean isAdmin) {
40                 this.username = SecurityManager.getInstance().calculateHash(usr);
41                 this.salt = SecurityManager.getInstance().generateSalt();
42                 this.password = SecurityManager.getInstance().calculateSaltedHash(pass.toCharArray(), this.salt);
43                 this.owner = null;
44                 this.admin = isAdmin;
45
46         }
47
48         public Account(String usr, String pass, Owner ow) {
49                 this.username = SecurityManager.getInstance().calculateHash(usr);
50                 this.salt = SecurityManager.getInstance().generateSalt();
51                 this.password = SecurityManager.getInstance().calculateSaltedHash(pass.toCharArray(),
52                                 this.salt);
53                 this.owner = ow;
54                 this.admin = false;
55
56         }
57
58         
59         public byte[] getUsername() {
60                 return username;
61         }
62
63         public byte[] getPassword() {
64                 return password;
65         }
66
67         public Owner getOwner() {
68                 return owner;
69         }
70
71         public boolean getAdmin() {
72                 return admin;
73         }
74
75         
76         public void setAdmin(boolean admin) {
77                 this.admin = admin;
78         }
79
80         public byte[] getSalt() {
81                 return salt;
82         }
83
84         public void setSalt(byte[] salt) {
85                 this.salt = salt;
86         }
87         
88
89         @Override
90         public boolean equals(Object obj) {
91                 if (this == obj)
92                         return true;
93                 if (obj == null)
94                         return false;
95                 if (getClass() != obj.getClass())
96                         return false;
97                 Account other = (Account) obj;
98                 if (!Arrays.equals(username, other.username))
99                         return false;
100                 return true;
101         }
102
103 }