blob: 54a595cdc68b4d9105f21c54e275541ab43c09b3 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
|
#!/usr/bin/env python3
import re
import sys
def strong_password(password: str) -> int:
"""The minimum number of steps required to make the given string very strong password.
Args:
password (str): The supplied password.
Returns:
int: The minimum number of steps required.
"""
# Count consecutive characters
cons_count = 0
for c in re.findall(r'((.)\2{2,})', password):
# For every 3 consecutive characters, we need to replace one
cons_count += len(c[0]) // 3
# Additional characters require to make it at least 6 characters
char_count = max(0, 6 - len(password))
# Count the number of missing character types
type_count = 0
if not re.search(r'[a-z]', password):
type_count += 1
if not re.search(r'[A-Z]', password):
type_count += 1
if not re.search(r'[0-9]', password):
type_count += 1
# Since the type change can be covered by one of the other required
# changes, return the maximum of the two
return max(cons_count + char_count, type_count)
def main():
result = strong_password(sys.argv[1])
print(result)
if __name__ == '__main__':
main()
|