Merge branch 'master' of https://xp-dev.com/git/RRRRHHHH_Code
[RRRRHHHH_Code] / ruralHouses / src / domain / Account.java
index f6f6460..08e841c 100644 (file)
 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 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, Owner ow){
+       public Account(byte[] usr){
                this.username = usr;
-               this.password= pass;
-               this.owner= ow;
+               this.salt =null;
+               this.password = null;
+               this.owner = null;
+               
+       }
+       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 = 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;
        }
 
        public Owner getOwner() {
                return owner;
        }
+
+       public boolean getAdmin() {
+               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;
+       }
+
 }