Ad
Puzzles
Regular Expressions
Puzzles
Regular Expressions
Code
Diff
  • import java.time.LocalDate;
    import java.time.format.DateTimeFormatter;
    import java.util.Arrays;
    
    public class PasswordValidation {
      
        private static final String TODAY_DATE = LocalDate.now().format(DateTimeFormatter.ofPattern("yyyyMMdd"));
    	  private static final String[] VALID_MONTHS = { "jan", "feb", "mar", "apr", "may", "jun", "jul", "aug", "sep", "oct",
    			"nov", "dec" };
      
      public static boolean validatePassword(String password) { 
        
        
        if (password.length() < 20 | password.length() > 50)
    			return false;
    		if (!isPrime(password.length()))
    			return false;
    		if (!password.contains(String.valueOf(password.length())))
    			return false;
    		if (!password.contains(TODAY_DATE))
    			return false;
    		if (!Arrays.stream(VALID_MONTHS).anyMatch(s -> password.toLowerCase().contains(s)))
    			return false;
    		if (password.matches("[A-Z]{0,2}|[^a-z]+|[^-._@#$&]+|.*[-._@#$&][-._@#$&].*"))
    			return false;
    		if (Arrays.stream(password.split("")).filter(s -> s.matches("[0-9]")).mapToInt(s -> Integer.valueOf(s)).sum() < 25)
    			return false;
    		return true;
      }
      
      public static boolean isPrime(int n) {
    		for (int i = 2; i <= Math.sqrt(n); i++) {
    			if (n % i == 0)
    				return false;
    		}
    		return true;
    	}
      
    }
    • import java.time.LocalDate;
    • import java.time.format.DateTimeFormatter;
    • import java.util.Arrays;
    • public class PasswordValidation {
    • public static boolean validatePassword(String password) {
    • // code here
    • return false;
    • private static final String TODAY_DATE = LocalDate.now().format(DateTimeFormatter.ofPattern("yyyyMMdd"));
    • private static final String[] VALID_MONTHS = { "jan", "feb", "mar", "apr", "may", "jun", "jul", "aug", "sep", "oct",
    • "nov", "dec" };
    • public static boolean validatePassword(String password) {
    • if (password.length() < 20 | password.length() > 50)
    • return false;
    • if (!isPrime(password.length()))
    • return false;
    • if (!password.contains(String.valueOf(password.length())))
    • return false;
    • if (!password.contains(TODAY_DATE))
    • return false;
    • if (!Arrays.stream(VALID_MONTHS).anyMatch(s -> password.toLowerCase().contains(s)))
    • return false;
    • if (password.matches("[A-Z]{0,2}|[^a-z]+|[^-._@#$&]+|.*[-._@#$&][-._@#$&].*"))
    • return false;
    • if (Arrays.stream(password.split("")).filter(s -> s.matches("[0-9]")).mapToInt(s -> Integer.valueOf(s)).sum() < 25)
    • return false;
    • return true;
    • }
    • public static boolean isPrime(int n) {
    • for (int i = 2; i <= Math.sqrt(n); i++) {
    • if (n % i == 0)
    • return false;
    • }
    • return true;
    • }
    • }
Puzzles
Regular Expressions
Code
Diff
  • public class PasswordValidation {
      
      public static boolean validatePassword(String password) {
        // code here
        return false;
      }
      
    }
    • public class PasswordValidation {
    • public static boolean validatePassword(String password) {
    • // code here
    • return false;
    • }
    • }