File tree Expand file tree Collapse file tree 2 files changed +39
-0
lines changed Expand file tree Collapse file tree 2 files changed +39
-0
lines changed Original file line number Diff line number Diff line change 1+ _5Y(|-nQ
Original file line number Diff line number Diff line change 1+ """
2+ random_password_gen.py
3+ A script to generate strong random passwords.
4+
5+ Usage:
6+ $ python random_password_gen.py
7+
8+ Author: Keshavraj Pore
9+ """
10+
11+ import random
12+ import string
13+
14+ def generate_password (length = 12 ):
15+ characters = string .ascii_letters + string .digits + string .punctuation
16+ password = '' .join (random .choice (characters ) for _ in range (length ))
17+ return password
18+
19+ def main ():
20+ print ("Random Password Generator" )
21+ try :
22+ length = int (input ("Enter desired password length: " ))
23+ if length < 6 :
24+ print (" Password length should be at least 6." )
25+ return
26+ password = generate_password (length )
27+ print (f"\n Generated Password: { password } " )
28+
29+ # Save to file
30+ with open ("passwords.txt" , "a" ) as file :
31+ file .write (password + "\n " )
32+ print (" Password saved to passwords.txt" )
33+
34+ except ValueError :
35+ print (" Please enter a valid number." )
36+
37+ if __name__ == "__main__" :
38+ main ()
You can’t perform that action at this time.
0 commit comments