Start a new Kumite
AllAgda (Beta)BF (Beta)CCFML (Beta)ClojureCOBOL (Beta)CoffeeScriptCommonLisp (Beta)CoqC++CrystalC#D (Beta)DartElixirElm (Beta)Erlang (Beta)Factor (Beta)Forth (Beta)Fortran (Beta)F#GoGroovyHaskellHaxe (Beta)Idris (Beta)JavaJavaScriptJulia (Beta)Kotlinλ Calculus (Beta)LeanLuaNASMNim (Beta)Objective-C (Beta)OCaml (Beta)Pascal (Beta)Perl (Beta)PHPPowerShell (Beta)Prolog (Beta)PureScript (Beta)PythonR (Beta)RacketRaku (Beta)Reason (Beta)RISC-V (Beta)RubyRustScalaShellSolidity (Beta)SQLSwiftTypeScriptVB (Beta)
Show only mine

Kumite (ko͞omiˌtā) is the practice of taking techniques learned from Kata and applying them through the act of freestyle sparring.

You can create a new kumite by providing some initial code and optionally some test cases. From there other warriors can spar with you, by enhancing, refactoring and translating your code. There is no limit to how many warriors you can spar with.

A great use for kumite is to begin an idea for a kata as one. You can collaborate with other code warriors until you have it right, then you can convert it to a kata.

Ad
Ad
Strings
Ciphers
Fundamentals
Cryptography
Algorithms
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;
    • }
    • }