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