package domain;
+import java.util.Arrays;
+
+import businessLogic.SecurityManager;
+
public class Account {
- private String username = "";
- private String password = "";
+
+
+ private byte[] username;
+ private byte[] password;
+ private byte[] salt;
+
private Owner owner;
private boolean admin = false;
- public Account(String usr, String pass, boolean admin) {
- this.username = usr;
- this.password = pass;
+
+ public Account(String usr){
+ this.username = SecurityManager.getInstance().calculateHash(usr);
+ this.salt =null;
+ this.password = null;
this.owner = null;
- this.admin = admin;
+
+ }
+ public Account(String usr, String pass, boolean isAdmin) {
+ this.username = SecurityManager.getInstance().calculateHash(usr);
+ this.salt = SecurityManager.getInstance().generateSalt();
+ this.password = SecurityManager.getInstance().calculateSaltedHash(pass.toCharArray(), this.salt);
+ this.owner = null;
+ this.admin = isAdmin;
}
public Account(String usr, String pass, Owner ow) {
- this.username = usr;
- this.password = pass;
+ this.username = SecurityManager.getInstance().calculateHash(usr);
+ this.salt = SecurityManager.getInstance().generateSalt();
+ this.password = SecurityManager.getInstance().calculateSaltedHash(pass.toCharArray(),
+ this.salt);
this.owner = ow;
this.admin = false;
}
- public String getUsername() {
+ public byte[] getUsername() {
return username;
}
- public String getPassword() {
+ public byte[] getPassword() {
return password;
}
this.admin = admin;
}
+ public byte[] getSalt() {
+ return salt;
+ }
+
+ public void setSalt(byte[] salt) {
+ this.salt = salt;
+ }
+
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj)
+ return true;
+ if (obj == null)
+ return false;
+ if (getClass() != obj.getClass())
+ return false;
+ Account other = (Account) obj;
+ if (!Arrays.equals(password, other.password))
+ return false;
+ if (!Arrays.equals(username, other.username))
+ return false;
+ return true;
+ }
+
}