Ad
Puzzles

The password game is a web game where you will write a password as it says, but it has a twist, you have to follow some insanely stupid rules to complete the perfect password.

So in this kata you will have a bunch of rules and need to make a method that validates if a String satisfies them all.

Input
  • A String or empty String
  • The given String will not have blank spaces or line breaks
Output
  • A boolean which state if the password is strong enough to pass the game
Rules
  • The maximum lenght of the password is 50 characters
  • The minimum lenght of the password is 20 characters
  • The length of the password must be a prime number
  • Must have at least 1 lower case, 3 upper case letter and 1 special character
  • The addition of each of the digits in the password has to be at least 25
  • Must have the diminituve of a month
  • Must have today's date
  • 2 special characters can't be together
  • The length of the password must be inside the password
Clarifications
  • The months of the year for this kata are [jan, feb, mar, apr, may, jun, jul, aug, sep, oct, nov, dec]
  • The months may be in upper case, lower case or combined
  • The date inside the password will have the following format YYYYMMDD
  • The date numbers count as normal digits
  • The special characters for this kata are ['-', '.' , '_', '@', '#', '$', '&']
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].*){3,}"))
            || !password.matches("(.*[a-z].*){1,}")
    				|| !password.matches("(.*[-._@#$&].*){1,}")
    				|| password.matches(".*[-._@#$&][-._@#$&].*"))
    			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 {
    • 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].*){3,}"))
    • || !password.matches("(.*[a-z].*){1,}")
    • || !password.matches("(.*[-._@#$&].*){1,}")
    • || password.matches(".*[-._@#$&][-._@#$&].*"))
    • 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
Puzzles
Regular Expressions

The password game is a web game where you will write a password as it says, but it has a twist, you have to follow some insanely stupid rules to complete the perfect password.

So in this kata you will have a bunch of those goofy ass rules and need to make a method that validates if a String satisfies them all.

Input
  • A string or maybe nothing...
  • The String will not have blank spaces or line breaks
Output
  • A boolean which state if the password is strong enough to pass the game
Rules
  • The maximum lenght of the password is 50 characters
  • The minimum lenght of the password is 20 characters
  • The length of the password must be a prime number
  • Must has at least 1 lower case, 3 upper case letter and 1 special character
  • The addition of each of the numbers in the password has to be equal or more than 25
  • Must have the diminituve of a month
  • Must have today's date
  • 2 special characters can't be together
  • The length of the password must be inside the password
Clarifications
  • The months of the year for this kata are [jan, feb, mar, apr, may, jun, jul, aug, sep, oct, nov, dec]
  • The months may be in upper case, lower case or combined
  • The date inside the password will have the following format YYYYMMDD
  • The date numbers count as normal numbers for the addition
Puzzles
Regular Expressions
Puzzles
Regular Expressions

The password game is a web game where you will write a password as it says, but it has a twist, you have to follow some insanely stupid rules to complete the perfect password.

So in this kata you will have a bunch of those goofy ass rules and need to make a method that validates if a String satisfies them all.

Input

  • A string, or maybe nothing...
Output
  • A boolean which state if the password is strong enough to pass the game
Rules
  • The maximum length of the password is 40 characters
  • The minimum length of the password is 15 characters
  • The length of the password must be a prime number
  • Must at least 1 lower case and 3 upper case letter, 1 number, 1 special character
  • The addition of each of the numbers in the password has to be equal or more than 25
  • Must have the diminituve of a month
  • Must have today's date
  • 2 special characters can't be together
  • The length of the password must be inside the password
Aclarations
  • The months of the year for this kata are -> [jan, feb, mar, apr, may, jun, jul, aug, sep, oct, nov, dec]
  • The date inside the password will have the following format YYYYMMDD
public class PasswordValidation {
  
  public static boolean validatePassword(String password) {
    return false;
  }
  
}