cleaning
[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(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         
52         public byte[] getUsername() {
53                 return username;
54         }
55
56         public byte[] getPassword() {
57                 return password;
58         }
59
60         public Owner getOwner() {
61                 return owner;
62         }
63
64         public boolean getAdmin() {
65                 return admin;
66         }
67
68         
69         public void setAdmin(boolean admin) {
70                 this.admin = admin;
71         }
72
73         public byte[] getSalt() {
74                 return salt;
75         }
76
77         public void setSalt(byte[] salt) {
78                 this.salt = salt;
79         }
80         
81
82         @Override
83         public boolean equals(Object obj) {
84                 if (this == obj)
85                         return true;
86                 if (obj == null)
87                         return false;
88                 if (getClass() != obj.getClass())
89                         return false;
90                 Account other = (Account) obj;
91                 if (!Arrays.equals(username, other.username))
92                         return false;
93                 return true;
94         }
95
96 }