Skip to content

Commit 6a529a6

Browse files
committed
Codewars kata
1 parent 63b7b48 commit 6a529a6

File tree

2 files changed

+43
-0
lines changed

2 files changed

+43
-0
lines changed

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ My code solutions to Codewars problems
1212
------------------------------ | ----------
1313
[Calculating With Functions](https://www.codewars.com/kata/525f3eda17c7cd9f9e000b39/train/python) | [Soluction](python/5_kyu/Calculating_With_Functions.py)
1414
[Write out numbers](https://www.codewars.com/kata/52724507b149fa120600031d/) | [Soluction](python/5_kyu/Write_out_numbers.py)
15+
[Regex Password Validation](https://www.codewars.com/kata/52e1476c8147a7547a000811) | [Soluction](python/5_kyu/Regex_Password_Validation.py)
1516

1617
**6-kyu**
1718
Problems/Kata | Solution
+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
# Kata link:
2+
# https://www.codewars.com/kata/52e1476c8147a7547a000811
3+
4+
# -------------------------------------
5+
# Instructions:
6+
'''
7+
You need to write regex that will validate a password to make sure it meets the following criteria:
8+
9+
At least six characters long
10+
contains a lowercase letter
11+
contains an uppercase letter
12+
contains a number
13+
Valid passwords will only be alphanumeric characters.
14+
15+
'''
16+
# -------------------------------------
17+
# Solution:
18+
19+
regex="^(?=.*[a-z])(?=.*[A-Z])(?=.*[0-9])[a-zA-Z\d]{6,}$"
20+
21+
22+
# -------------------------------------
23+
# Basic Tests
24+
from re import search
25+
print(bool(search(regex, 'fjd3IR9')), True)
26+
print(bool(search(regex, 'ghdfj32')), False)
27+
print(bool(search(regex, 'DSJKHD23')), False)
28+
print(bool(search(regex, 'dsF43')), False)
29+
print(bool(search(regex, '4fdg5Fj3')), True)
30+
print(bool(search(regex, 'DHSJdhjsU')), False)
31+
print(bool(search(regex, 'fjd3IR9.;')), False)
32+
print(bool(search(regex, 'fjd3 IR9')), False)
33+
print(bool(search(regex, 'djI38D55')), True)
34+
print(bool(search(regex, 'a2.d412')), False)
35+
print(bool(search(regex, 'JHD5FJ53')), False)
36+
print(bool(search(regex, '!fdjn345')), False)
37+
print(bool(search(regex, 'jfkdfj3j')), False)
38+
print(bool(search(regex, '123')), False)
39+
print(bool(search(regex, 'abc')), False)
40+
print(bool(search(regex, '123abcABC')), True)
41+
print(bool(search(regex, 'ABC123abc')), True)
42+
print(bool(search(regex, 'Password123')), True)

0 commit comments

Comments
 (0)