Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions kata/5-kyu/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
9 changes: 9 additions & 0 deletions kata/5-kyu/regex-password-validation/README.md
Original file line number Diff line number Diff line change
@@ -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)
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
final class PasswordRegex {
static final String REGEX = "(?=.*[a-z])(?=.*[A-Z])(?=.*\\d)[a-zA-Z\\d]{6,}";

private PasswordRegex() {}
}
41 changes: 41 additions & 0 deletions kata/5-kyu/regex-password-validation/test/SolutionTest.java
Original file line number Diff line number Diff line change
@@ -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));
}
}