Skip to content

Commit 54adfbd

Browse files
Merge pull request #2797 from Keshavraj52/add-password-generator
Added random password generator python script
2 parents ed5c017 + 9f60cc2 commit 54adfbd

File tree

2 files changed

+39
-0
lines changed

2 files changed

+39
-0
lines changed

passwords.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
_5Y(|-nQ

random_password_gen.py

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
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"\nGenerated 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()

0 commit comments

Comments
 (0)