bugfix3
[staff/due1/sed-hs15-srs-purple.git] / src / main / java / ch / bfh / ti / srs / core / User.java
CommitLineData
0a2e269c
M
1package ch.bfh.ti.srs.core;
2
3public class User {
9ca2608d 4
0a2e269c
M
5 private final String userName;
6 private String password;
9ca2608d
M
7 private String mail;
8 private String name;
9 private String lastname;
10
11
12 public User(String userName, String password){
13 this.userName = userName;
14 try {
15 this.password = Password.getSaltedHash(password);
16 } catch (Exception e) {
17 System.err.println("Fehler beim erstellen des Hashes");
18 }
0a2e269c 19 }
9ca2608d 20
0a2e269c
M
21 public String getUserName(){
22 return userName;
23 }
9ca2608d 24
0a2e269c 25 public boolean checkPassword(String password){
9ca2608d
M
26 boolean passwordCorrect = false;
27 try {
28 passwordCorrect = Password.check(password, this.password);
29 } catch (Exception e) {
30 System.err.println("Fehler beim Prüfen des Passwortes");
31 }
32 return passwordCorrect;
33 }
34
35 public boolean setMail(String mail){
36 if(isValidEmailAddress(mail)){
37 this.mail = mail;
38 return true;
39 }
40 return false;
41 }
42
43 public String getMail(){
44 return mail;
45 }
46
47 public void changePassword(String newPassword){
48 try {
49 this.password = Password.getSaltedHash(newPassword);
50 } catch (Exception e) {
51 System.err.println("Fehler beim erstellen des Hashes");
52 }
53 }
54
55 public String getName() {
56 return name;
57 }
58
59 public void setName(String name) {
60 this.name = name;
61 }
62
63 public String getLastname() {
64 return lastname;
65 }
66
67 public void setLastname(String lastName) {
68 this.lastname = lastname;
69 }
70
71 private boolean isValidEmailAddress(String mail){
72 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,}))$";
73 java.util.regex.Pattern p = java.util.regex.Pattern.compile(ePattern);
74 java.util.regex.Matcher m = p.matcher(mail);
75 return m.matches();
0a2e269c
M
76 }
77}