diff --git a/kata/5-kyu/index.md b/kata/5-kyu/index.md index 14af678c..3735ad66 100644 --- a/kata/5-kyu/index.md +++ b/kata/5-kyu/index.md @@ -38,6 +38,7 @@ - [Pick peaks](pick-peaks "5279f6fe5ab7f447890006a7") - [Primes in numbers](primes-in-numbers "54d512e62a5e54c96200019e") - [Product of consecutive Fib numbers](product-of-consecutive-fib-numbers "5541f58a944b85ce6d00006a") +- [Regex Password Validation](regex-password-validation "52e1476c8147a7547a000811") - [RGB To Hex Conversion](rgb-to-hex-conversion "513e08acc600c94f01000001") - [Rot13](rot13-1 "530e15517bc88ac656000716") - [ROT13](rot13 "52223df9e8f98c7aa7000062") diff --git a/kata/5-kyu/regex-password-validation/README.md b/kata/5-kyu/regex-password-validation/README.md new file mode 100644 index 00000000..a4cf42be --- /dev/null +++ b/kata/5-kyu/regex-password-validation/README.md @@ -0,0 +1,9 @@ +# [Regex Password Validation](https://www.codewars.com/kata/regex-password-validation "https://www.codewars.com/kata/52e1476c8147a7547a000811") + +You need to write regex that will validate a password to make sure it meets the following criteria: + +* At least six characters long +* contains a lowercase letter +* contains an uppercase letter +* contains a digit +* only contains alphanumeric characters (note that `'_'` is not alphanumeric) \ No newline at end of file diff --git a/kata/5-kyu/regex-password-validation/main/PasswordRegex.java b/kata/5-kyu/regex-password-validation/main/PasswordRegex.java new file mode 100644 index 00000000..0f2ab068 --- /dev/null +++ b/kata/5-kyu/regex-password-validation/main/PasswordRegex.java @@ -0,0 +1,5 @@ +final class PasswordRegex { + static final String REGEX = "(?=.*[a-z])(?=.*[A-Z])(?=.*\\d)[a-zA-Z\\d]{6,}"; + + private PasswordRegex() {} +} \ No newline at end of file diff --git a/kata/5-kyu/regex-password-validation/test/SolutionTest.java b/kata/5-kyu/regex-password-validation/test/SolutionTest.java new file mode 100644 index 00000000..5f91b876 --- /dev/null +++ b/kata/5-kyu/regex-password-validation/test/SolutionTest.java @@ -0,0 +1,41 @@ +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; + +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.ValueSource; + +class SolutionTest { + @ParameterizedTest + @ValueSource(strings = { + "fjd3IR9", + "4fdg5Fj3", + "djI38D55", + "123abcABC", + "ABC123abc", + "Password123" + }) + void valid(String password) { + assertTrue(password.matches(PasswordRegex.REGEX)); + } + + @ParameterizedTest + @ValueSource(strings = { + "ghdfj32", + "DSJKHD23", + "dsF43", + "DHSJdhjsU", + "fjd3IR9.;", + "fjd3 IR9", + "djI3_8D55", + "@@", + "JHD5FJ53", + "!fdjn345", + "jfkdfj3j", + "123", + "abc", + "" + }) + void invalid(String password) { + assertFalse(password.matches(PasswordRegex.REGEX)); + } +} \ No newline at end of file