File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 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
62import 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: " ))))
You can’t perform that action at this time.
0 commit comments