Skip to content

Commit 663c6f1

Browse files
rootroot
authored andcommitted
Added features to the password generator
New support for digits and special characters
1 parent bcca248 commit 663c6f1

File tree

1 file changed

+21
-10
lines changed

1 file changed

+21
-10
lines changed

Password Generator/pass_gen.py

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,24 @@
1-
'''
2-
The secrets module is used for generating cryptographically strong random numbers suitable for managing data such as passwords,
3-
account authentication, security tokens, and related secrets.
4-
'''
5-
import string
1+
import string as str
62
import secrets
3+
class PasswordGenerator():
74

8-
def secure_password_gen(passlength):
9-
password = ''.join((secrets.choice(string.ascii_letters) for i in range(passlength)))
10-
return password
5+
@staticmethod
6+
def set_sequence(*conditions): #must have 4 conditions, one for each menber of the list possible_characters
7+
possible_characters=[str.ascii_lowercase, str.ascii_uppercase, str.digits, str.punctuation]
8+
sequence=""
9+
for x in range(len(conditions)):
10+
if conditions[x]:
11+
sequence+=possible_characters[x]
12+
else:
13+
pass
14+
return sequence
1115

12-
n = int(input('Enter length of password : '))
13-
print('Password generated is :', secure_password_gen(n))
16+
17+
@staticmethod
18+
def secure_password_gen(passlength=8, ):
19+
characters_for_password = PasswordGenerator.set_sequence(True, True, True, True)
20+
password = ''.join((secrets.choice(characters_for_password) for i in range(passlength)))
21+
return password
22+
23+
while True:
24+
print('Password generated is :', PasswordGenerator.secure_password_gen(int(input("Enter password lenght: "))))

0 commit comments

Comments
 (0)