Merge conflicts solutioned
[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(String usr){
26                 this.username = SecurityManager.getInstance().calculateHash(usr);
27                 this.salt =null;
28                 this.password = null;
29                 this.owner = null;
30                 
31         }
32         public Account(String usr, String pass, boolean isAdmin) {
33                 this.username = SecurityManager.getInstance().calculateHash(usr);
34                 this.salt = SecurityManager.getInstance().generateSalt();
35                 this.password = SecurityManager.getInstance().calculateSaltedHash(pass.toCharArray(), this.salt);
36                 this.owner = null;
37                 this.admin = isAdmin;
38
39         }
40
41         public Account(String usr, String pass, Owner ow) {
42                 this.username = SecurityManager.getInstance().calculateHash(usr);
43                 this.salt = SecurityManager.getInstance().generateSalt();
44                 this.password = SecurityManager.getInstance().calculateSaltedHash(pass.toCharArray(),
45                                 this.salt);
46                 this.owner = ow;
47                 this.admin = false;
48
49         }
50
51         public byte[] getUsername() {
52                 return username;
53         }
54
55         public byte[] getPassword() {
56                 return password;
57         }
58
59         public Owner getOwner() {
60                 return owner;
61         }
62
63         public boolean getAdmin() {
64                 return admin;
65         }
66
67         public void setAdmin(boolean admin) {
68                 this.admin = admin;
69         }
70
71         public byte[] getSalt() {
72                 return salt;
73         }
74
75         public void setSalt(byte[] salt) {
76                 this.salt = salt;
77         }
78         
79
80         @Override
81         public boolean equals(Object obj) {
82                 if (this == obj)
83                         return true;
84                 if (obj == null)
85                         return false;
86                 if (getClass() != obj.getClass())
87                         return false;
88                 Account other = (Account) obj;
89                 if (!Arrays.equals(password, other.password))
90                         return false;
91                 if (!Arrays.equals(username, other.username))
92                         return false;
93                 return true;
94         }
95
96 }