l_evandro

SenhaForte

Feb 19th, 2022
1,053
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.50 KB | None | 0 0
  1. package duvida;
  2.  
  3. public class SenhaForte {
  4.     public static void main(String[] args) {
  5.         String str = "Ya5";
  6.         if (validandoTamanho(str) && verificandoDigito(str) && verificaLetraMaiuscula(str)
  7.                 && verificaLetraMinuscula(str) && verificandoDigito(str))
  8.             System.out.println("Senha segura!");
  9.         else {
  10.             System.out.printf("Senha não e forte!\n");
  11.             if (str.length() < 6) {
  12.                 System.out.printf("Sua senha precisa ter mais %d caracteres", 6 - str.length());
  13.             }
  14.         }
  15.     }
  16.  
  17.     public static boolean validandoTamanho(String s) {
  18.         return (s.length() >= 6);
  19.     }
  20.  
  21.     public static boolean verificandoDigito(String s) {
  22.         char[] ch = s.toCharArray();
  23.         for (int i = 0; i < ch.length; i++) {
  24.             if (String.valueOf(ch[i]).matches("\\d+"))
  25.                 return true;
  26.         }
  27.         return false;
  28.     }
  29.  
  30.     public static boolean verificaLetraMaiuscula(String s) {
  31.         char[] ch = s.toCharArray();
  32.         for (int i = 0; i < ch.length; i++) {
  33.             if (String.valueOf(ch[i]).matches("\\p{Upper}+"))
  34.                 return true;
  35.         }
  36.         return false;
  37.     }
  38.  
  39.     public static boolean verificaLetraMinuscula(String s) {
  40.         char[] ch = s.toCharArray();
  41.         for (int i = 0; i < ch.length; i++) {
  42.             new String();
  43.             if (String.valueOf(ch[i]).matches("\\p{Lower}+"))
  44.                 return true;
  45.         }
  46.         return false;
  47.     }
  48.  
  49.     public static boolean verificaCaracterEspecial(String s) {
  50.         char[] ch = s.toCharArray();
  51.         for (int i = 0; i < ch.length; i++) {
  52.             new String();
  53.             if (String.valueOf(ch[i]).matches("\\p{Punct}+"))
  54.                 return true;
  55.         }
  56.         return false;
  57.     }
  58. }
Advertisement
Add Comment
Please, Sign In to add comment