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