Username is saved hashed and password hashed and salted
[RRRRHHHH_Code] / ruralHouses / src / domain / Account.java
1 package domain;
2
3 import businessLogic.SecurityManager;
4
5 public class Account {
6
7         private byte[] username;
8         private byte[] password;
9         private byte[] salt;
10
11         private Owner owner;
12         private boolean admin = false;
13
14         
15         public Account(String usr){
16                 this.username = SecurityManager.getInstance().calculateHash(usr);
17                 this.salt =null;
18                 this.password = null;
19                 this.owner = null;
20                 
21         }
22         public Account(String usr, String pass, boolean isAdmin) {
23                 this.username = SecurityManager.getInstance().calculateHash(usr);
24                 this.salt = SecurityManager.getInstance().generateSalt();
25                 this.password = SecurityManager.getInstance().calculateSaltedHash(pass.toCharArray(), this.salt);
26                 this.owner = null;
27                 this.admin = isAdmin;
28
29         }
30
31         public Account(String usr, String pass, Owner ow) {
32                 this.username = SecurityManager.getInstance().calculateHash(usr);
33                 this.salt = SecurityManager.getInstance().generateSalt();
34                 this.password = SecurityManager.getInstance().calculateSaltedHash(pass.toCharArray(),
35                                 this.salt);
36                 this.owner = ow;
37                 this.admin = false;
38
39         }
40
41         public byte[] getUsername() {
42                 return username;
43         }
44
45         public byte[] getPassword() {
46                 return password;
47         }
48
49         public Owner getOwner() {
50                 return owner;
51         }
52
53         public boolean getAdmin() {
54                 return admin;
55         }
56
57         public void setAdmin(boolean admin) {
58                 this.admin = admin;
59         }
60
61         public byte[] getSalt() {
62                 return salt;
63         }
64
65         public void setSalt(byte[] salt) {
66                 this.salt = salt;
67         }
68
69 }