tiagooleite2

Untitled

Nov 15th, 2020
644
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.05 KB | None | 0 0
  1. package expressaoregular;
  2.  
  3. import java.util.regex.Matcher;
  4. import java.util.regex.Pattern;
  5.  
  6. public class MascaraValidacaoSenha {
  7.  
  8.     public static boolean ehSenhaValida(String senha) {
  9.         if (senha == null || senha.trim().isEmpty()
  10.                 || senha.trim().length() != 8) {
  11.             return false;
  12.         }
  13.        
  14.         if (contemCharAlfanumerico(senha) && contemObrigatorioMaisculoNumero(senha)) {
  15.             return true;
  16.         }
  17.         return false;
  18.     }
  19.    
  20.     private static boolean contemObrigatorioMaisculoNumero(String senha) {
  21.         Pattern pattern = Pattern.compile("[A-Z]+");
  22.         Matcher matcher = pattern.matcher(senha);
  23.        
  24.         Pattern patternNumero = Pattern.compile("\\d+");
  25.         Matcher matcherNumero = patternNumero.matcher(senha);
  26.        
  27.         if (matcher.find() && matcherNumero.find()){
  28.             return true;
  29.         }
  30.         return false;
  31.     }
  32.  
  33.     private static boolean contemCharAlfanumerico(String senha) {
  34.         Pattern pattern = Pattern.compile("\\W+");
  35.         Matcher matcher = pattern.matcher(senha);
  36.        
  37.         if (matcher.find()){
  38.             return false;
  39.         }
  40.        
  41.         return true;
  42.     }
  43.    
  44. }
  45.  
Advertisement
Add Comment
Please, Sign In to add comment