File tree Expand file tree Collapse file tree 4 files changed +56
-0
lines changed
regex-password-validation Expand file tree Collapse file tree 4 files changed +56
-0
lines changed Original file line number Diff line number Diff line change 3838- [ Pick peaks] ( pick-peaks " 5279f6fe5ab7f447890006a7 ")
3939- [ Primes in numbers] ( primes-in-numbers " 54d512e62a5e54c96200019e ")
4040- [ Product of consecutive Fib numbers] ( product-of-consecutive-fib-numbers " 5541f58a944b85ce6d00006a ")
41+ - [ Regex Password Validation] ( regex-password-validation " 52e1476c8147a7547a000811 ")
4142- [ RGB To Hex Conversion] ( rgb-to-hex-conversion " 513e08acc600c94f01000001 ")
4243- [ Rot13] ( rot13-1 " 530e15517bc88ac656000716 ")
4344- [ ROT13] ( rot13 " 52223df9e8f98c7aa7000062 ")
Original file line number Diff line number Diff line change 1+ # [ Regex Password Validation] ( https://www.codewars.com/kata/regex-password-validation " https://www.codewars.com/kata/52e1476c8147a7547a000811 ")
2+
3+ You need to write regex that will validate a password to make sure it meets the following criteria:
4+
5+ * At least six characters long
6+ * contains a lowercase letter
7+ * contains an uppercase letter
8+ * contains a digit
9+ * only contains alphanumeric characters (note that ` '_' ` is not alphanumeric)
Original file line number Diff line number Diff line change 1+ final class PasswordRegex {
2+ static final String REGEX = "(?=.*[a-z])(?=.*[A-Z])(?=.*\\ d)[a-zA-Z\\ d]{6,}" ;
3+
4+ private PasswordRegex () {}
5+ }
Original file line number Diff line number Diff line change 1+ import static org .junit .jupiter .api .Assertions .assertFalse ;
2+ import static org .junit .jupiter .api .Assertions .assertTrue ;
3+
4+ import org .junit .jupiter .params .ParameterizedTest ;
5+ import org .junit .jupiter .params .provider .ValueSource ;
6+
7+ class SolutionTest {
8+ @ ParameterizedTest
9+ @ ValueSource (strings = {
10+ "fjd3IR9" ,
11+ "4fdg5Fj3" ,
12+ "djI38D55" ,
13+ "123abcABC" ,
14+ "ABC123abc" ,
15+ "Password123"
16+ })
17+ void valid (String password ) {
18+ assertTrue (password .matches (PasswordRegex .REGEX ));
19+ }
20+
21+ @ ParameterizedTest
22+ @ ValueSource (strings = {
23+ "ghdfj32" ,
24+ "DSJKHD23" ,
25+ "dsF43" ,
26+ "DHSJdhjsU" ,
27+ "fjd3IR9.;" ,
28+ "fjd3 IR9" ,
29+ "djI3_8D55" ,
30+ "@@" ,
31+ "JHD5FJ53" ,
32+ "!fdjn345" ,
33+ "jfkdfj3j" ,
34+ "123" ,
35+ "abc" ,
36+ ""
37+ })
38+ void invalid (String password ) {
39+ assertFalse (password .matches (PasswordRegex .REGEX ));
40+ }
41+ }
You can’t perform that action at this time.
0 commit comments