PageRenderTime 57ms CodeModel.GetById 23ms RepoModel.GetById 1ms app.codeStats 0ms

/src/sk/ibm/sa/utils/LoginUtils.java

https://gitlab.com/unique_steve/IBMWinter
Java | 35 lines | 29 code | 6 blank | 0 comment | 0 complexity | caae552c852a123eec6fd833c7109489 MD5 | raw file
  1. package sk.ibm.sa.utils;
  2. import java.math.BigInteger;
  3. import java.security.MessageDigest;
  4. import java.security.NoSuchAlgorithmException;
  5. import java.util.regex.Matcher;
  6. import java.util.regex.Pattern;
  7. import javax.faces.context.FacesContext;
  8. import javax.servlet.http.HttpSession;
  9. public class LoginUtils {
  10. public static final Pattern VALID_EMAIL_ADDRESS_REGEX = Pattern.compile("^[A-Z0-9._%+-]+@[A-Z0-9.-]+\\.[A-Z]{2,6}$",
  11. Pattern.CASE_INSENSITIVE);
  12. public static boolean isEmailValid(String email) {
  13. Matcher matcher = VALID_EMAIL_ADDRESS_REGEX.matcher(email);
  14. return matcher.find();
  15. }
  16. public static String hash(String s) {
  17. try {
  18. MessageDigest md = MessageDigest.getInstance("md5");
  19. md.reset();
  20. md.update(s.getBytes());
  21. byte[] digest = md.digest();
  22. BigInteger bigInt = new BigInteger(1, digest);
  23. return bigInt.toString(16);
  24. } catch (NoSuchAlgorithmException e) {
  25. e.printStackTrace();
  26. return null;
  27. }
  28. }
  29. }