Problems when accepting bookings fixed
[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         public void setAdmin(boolean admin) {
69                 this.admin = admin;
70         }
71
72         public byte[] getSalt() {
73                 return salt;
74         }
75
76         public void setSalt(byte[] salt) {
77                 this.salt = salt;
78         }
79         
80
81         @Override
82         public boolean equals(Object obj) {
83                 if (this == obj)
84                         return true;
85                 if (obj == null)
86                         return false;
87                 if (getClass() != obj.getClass())
88                         return false;
89                 Account other = (Account) obj;
90                 if (!Arrays.equals(username, other.username))
91                         return false;
92                 return true;
93         }
94
95 }