User class updated
authorMatthias <balmm1@bfh.ch>
Wed, 21 Oct 2015 09:38:02 +0000 (11:38 +0200)
committerMatthias <balmm1@bfh.ch>
Wed, 21 Oct 2015 09:38:02 +0000 (11:38 +0200)
src/main/java/ch/bfh/ti/srs/core/User.java

index e1fd775..feac488 100644 (file)
@@ -1,20 +1,77 @@
 package ch.bfh.ti.srs.core;
 
 public class User {
-       
+
        private final String userName;
        private String password;
-       
-       public User(String name, String password){
-               this.userName = name;
-               this.password = password;
+       private String mail;
+       private String name;
+       private String lastname;
+
+
+       public User(String userName, String password){
+               this.userName = userName;
+               try {
+                       this.password = Password.getSaltedHash(password);
+               } catch (Exception e) {
+                       System.err.println("Fehler beim erstellen des Hashes");
+               }
        }
-       
+
        public String getUserName(){
                return userName;
        }
-       
+
        public boolean checkPassword(String password){
-               return Password.checkPassword(password, this.password);
+               boolean passwordCorrect = false;
+               try {
+                       passwordCorrect = Password.check(password, this.password);
+               } catch (Exception e) {
+                       System.err.println("Fehler beim Prüfen des Passwortes");
+               }
+               return passwordCorrect;
+       }
+
+       public boolean setMail(String mail){
+               if(isValidEmailAddress(mail)){
+                       this.mail = mail;
+                       return true;
+               }
+               return false;
+       }
+
+       public String getMail(){
+               return mail;
+       }
+
+       public void changePassword(String newPassword){
+               try {
+                       this.password = Password.getSaltedHash(newPassword);
+               } catch (Exception e) {
+                       System.err.println("Fehler beim erstellen des Hashes");
+               }
+       }
+
+       public String getName() {
+               return name;
+       }
+
+       public void setName(String name) {
+               this.name = name;
+       }
+
+       public String getLastname() {
+               return lastname;
+       }
+
+       public void setLastname(String lastName) {
+               this.lastname = lastname;
+       }
+
+       private boolean isValidEmailAddress(String mail){
+               String ePattern = "^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@((\\[[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\])|(([a-zA-Z\\-0-9]+\\.)+[a-zA-Z]{2,}))$";
+               java.util.regex.Pattern p = java.util.regex.Pattern.compile(ePattern);
+               java.util.regex.Matcher m = p.matcher(mail);
+               return m.matches();
        }
 }
\ No newline at end of file