From cfe34088002dc0d1b50845110828b241033b861f Mon Sep 17 00:00:00 2001 From: ParanoidUser <5120290+ParanoidUser@users.noreply.github.com> Date: Thu, 8 May 2025 03:07:28 +0000 Subject: [PATCH 1/3] docs: kata description --- kata/5-kyu/index.md | 1 + kata/5-kyu/regex-password-validation/README.md | 9 +++++++++ 2 files changed, 10 insertions(+) create mode 100644 kata/5-kyu/regex-password-validation/README.md 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..601837a5 --- /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) From d565759391bcd463999994ada089c706166b282a Mon Sep 17 00:00:00 2001 From: "Capt. Cutlass" <5120290+ParanoidUser@users.noreply.github.com> Date: Wed, 7 May 2025 23:56:45 -0400 Subject: [PATCH 2/3] feat: kata/regex-password-validation --- .../5-kyu/regex-password-validation/README.md | 2 +- .../main/PasswordRegex.java | 3 ++ .../test/SolutionTest.java | 41 +++++++++++++++++++ 3 files changed, 45 insertions(+), 1 deletion(-) create mode 100644 kata/5-kyu/regex-password-validation/main/PasswordRegex.java create mode 100644 kata/5-kyu/regex-password-validation/test/SolutionTest.java diff --git a/kata/5-kyu/regex-password-validation/README.md b/kata/5-kyu/regex-password-validation/README.md index 601837a5..a4cf42be 100644 --- a/kata/5-kyu/regex-password-validation/README.md +++ b/kata/5-kyu/regex-password-validation/README.md @@ -6,4 +6,4 @@ You need to write regex that will validate a password to make sure it meets the * contains a lowercase letter * contains an uppercase letter * contains a digit -* only contains alphanumeric characters (note that `'_'` is not alphanumeric) +* 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..11393537 --- /dev/null +++ b/kata/5-kyu/regex-password-validation/main/PasswordRegex.java @@ -0,0 +1,3 @@ +interface PasswordRegex { + String REGEX = "^(?=.*[a-z])(?=.*[A-Z])(?=.*\\d)[a-zA-Z\\d]{6,}$"; +} \ 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 From c91a162faaead3e081766570121526c507a94316 Mon Sep 17 00:00:00 2001 From: "Capt. Cutlass" <5120290+ParanoidUser@users.noreply.github.com> Date: Thu, 8 May 2025 13:18:42 -0400 Subject: [PATCH 3/3] refactor: move constants defined in this interfaces to another class or enum. --- .../5-kyu/regex-password-validation/main/PasswordRegex.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/kata/5-kyu/regex-password-validation/main/PasswordRegex.java b/kata/5-kyu/regex-password-validation/main/PasswordRegex.java index 11393537..0f2ab068 100644 --- a/kata/5-kyu/regex-password-validation/main/PasswordRegex.java +++ b/kata/5-kyu/regex-password-validation/main/PasswordRegex.java @@ -1,3 +1,5 @@ -interface PasswordRegex { - String REGEX = "^(?=.*[a-z])(?=.*[A-Z])(?=.*\\d)[a-zA-Z\\d]{6,}$"; +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