Skip to content

Commit f829801

Browse files
author
BabyEntchen
committed
New example
1 parent fb9c6af commit f829801

File tree

1 file changed

+47
-0
lines changed

1 file changed

+47
-0
lines changed
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
from string_py import Str, Color
2+
import string
3+
4+
5+
class PasswordManager:
6+
def __init__(self, password: Str):
7+
self.password = password
8+
9+
@staticmethod
10+
def generate_password() -> str:
11+
return Str(string.ascii_letters + string.digits + ".,?!$#").generate(min_=20, max_=30)
12+
13+
def calc_strength(self, points: int):
14+
print(points)
15+
if points < 5:
16+
print("Very Bad! you should use a new password. Example: ", Color.basic,
17+
self.generate_password())
18+
elif points >= 5:
19+
print("Bad! you should use a new password. Example: " + Color.basic,
20+
self.generate_password())
21+
elif points <= 13:
22+
print("You password is okay. Maybe use a new password. Example: " + self.generate_password())
23+
else:
24+
print("Your password is fine!")
25+
26+
def check_password(self):
27+
points = 0
28+
if len(self.password) < 8:
29+
return self.calc_strength(points)
30+
else:
31+
points += 0.5 * len(self.password)
32+
if self.password.get_numeric(chars=False) == 0:
33+
points -= 1
34+
if self.password.get_upper(chars=False) == 0:
35+
points -= 1
36+
if self.password.get_lower(chars=False) == 0:
37+
points -= 1
38+
if self.password.get_punctuation(chars=False) == 0:
39+
points -= 1
40+
else:
41+
points += 10
42+
return self.calc_strength(round(points))
43+
44+
45+
if __name__ == "__main__":
46+
PasswordManager(Str(input("Your password: "))).check_password()
47+

0 commit comments

Comments
 (0)