Merge branch 'master' of https://xp-dev.com/git/RRRRHHHH_Code
[RRRRHHHH_Code] / ruralHouses / src / domain / Account.java
index e0727a1..08e841c 100644 (file)
@@ -1,33 +1,66 @@
 package domain;
 
-public class Account {
+import java.io.Serializable;
+import java.util.Arrays;
+
+import businessLogic.SecurityManager;
+
+public class Account implements Serializable {
+
+       /**
+        * 
+        */
+       private static final long serialVersionUID = 1L;
+       
+
+       private byte[] username;
+       private byte[] password;
+       private byte[] salt;
+
 
-       private String username = "";
-       private String password = "";
        private Owner owner;
        private boolean admin = false;
 
-       public Account(String usr, String pass, boolean admin) {
+       
+       public Account(byte[] usr){
                this.username = usr;
-               this.password = pass;
+               this.salt =null;
+               this.password = null;
                this.owner = null;
-               this.admin = admin;
+               
+       }
+       public Account(Owner own){
+               this.username = null;
+               this.salt =null;
+               this.password = null;
+               this.owner = own;
+               
+       }
+       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;
        }
 
@@ -39,8 +72,32 @@ public class Account {
                return admin;
        }
 
+       
        public void setAdmin(boolean admin) {
                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(username, other.username))
+                       return false;
+               return true;
+       }
+
 }