|
|
|
@ -3,7 +3,9 @@ package de.t_battermann.dhbw.todolist;
|
|
|
|
|
import org.apache.commons.codec.digest.DigestUtils;
|
|
|
|
|
import org.apache.commons.validator.routines.EmailValidator;
|
|
|
|
|
|
|
|
|
|
import java.util.*;
|
|
|
|
|
import java.util.LinkedList;
|
|
|
|
|
import java.util.List;
|
|
|
|
|
import java.util.UUID;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* This class contains all the users data.
|
|
|
|
@ -48,6 +50,24 @@ public class User {
|
|
|
|
|
this.todoLists = new LinkedList<>();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Checks if eMail has correct syntax
|
|
|
|
|
*
|
|
|
|
|
* @param email string containing a eMail address
|
|
|
|
|
* @return true if valid syntax
|
|
|
|
|
*/
|
|
|
|
|
public static boolean checkEmail(String email) {
|
|
|
|
|
return email.length() != 0 && EmailValidator.getInstance().isValid(email);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static boolean checkUsername(String username) {
|
|
|
|
|
return username.matches("[a-zA-Z0-9_-]{3,}");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static boolean checkPassword(String password) {
|
|
|
|
|
return password.length() > 6 && password.matches(".*[A-Z].*") && password.matches(".*[a-z].*") && password.matches(".*[0-9].*");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Gets username.
|
|
|
|
|
*
|
|
|
|
@ -66,6 +86,15 @@ public class User {
|
|
|
|
|
return this.password;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Update the users password
|
|
|
|
|
*
|
|
|
|
|
* @param password the password (cleartext)
|
|
|
|
|
*/
|
|
|
|
|
public void setPassword(String password) {
|
|
|
|
|
this.password = hashPassword(password);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Gets uuid.
|
|
|
|
|
*
|
|
|
|
@ -139,15 +168,6 @@ public class User {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Update the users password
|
|
|
|
|
*
|
|
|
|
|
* @param password the password (cleartext)
|
|
|
|
|
*/
|
|
|
|
|
public void setPassword(String password) {
|
|
|
|
|
this.password = hashPassword(password);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Sets email.
|
|
|
|
|
*
|
|
|
|
@ -172,20 +192,4 @@ public class User {
|
|
|
|
|
private String hashPassword(String password) {
|
|
|
|
|
return DigestUtils.sha256Hex(uuid + password);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Checks if eMail has correct syntax
|
|
|
|
|
* @param email string containing a eMail address
|
|
|
|
|
* @return true if valid syntax
|
|
|
|
|
*/
|
|
|
|
|
public static boolean checkEmail(String email) {
|
|
|
|
|
return email.length() != 0 && EmailValidator.getInstance().isValid(email);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static boolean checkUsername(String username) {
|
|
|
|
|
return username.matches("[a-zA-Z0-9_-]{3,}");
|
|
|
|
|
}
|
|
|
|
|
public static boolean checkPassword(String password) {
|
|
|
|
|
return password.length() > 6 && password.matches(".*[A-Z].*") && password.matches(".*[a-z].*") && password.matches(".*[0-9].*");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|