-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcodsoft_task3_rand_password_gen.py
70 lines (57 loc) · 1.91 KB
/
codsoft_task3_rand_password_gen.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#COMMAND LINE APPLICATION TO GENERATE RANDOM PASSWORD
#Author : Jatoth Adithya Naik
#for : Intenship (TASK-3)
# Discription :
# this command appplication generates random password
# user has to give length of the password as input
# importing random AND string modules
import random
import string
def main():
print("\n\n\t\t\tby @JATOTH ADITHYA NAIK")
print("________________________________________")
print("\n\t\t\t***RANDOM PASSWORD GENERATOR APP***\n")
# taking usename from the user
username = input("\tEnter the user name : ")
# taking the length of desired password
length = input("\n\tEnter the length of the password : ")
while True:
# empty password
password = ""
if length.isdigit():
if length == "0":
print("\n\t\tInvalid size\n")
exit()
else:
gen(length,password)
break
else:
print("\n\t\tInvalid size\n")
exit()
while True:
choice = rep()
match choice:
case "1" :
print("\n\t\tTHANKS FOR USING....\n")
exit()
case "2" :
gen(length,password)
case "3" :
print("\n\t\tTHANKS FOR USING....\n")
exit()
case _ :
print("\n\tInvalid choice\n")
break
print("\n\t\tTHANKS FOR USING....\n")
# function for generating the password of given length
def gen(length,password):
all_chars = string.ascii_letters + string.digits + string.punctuation
for i in range(int(length)):
password+=random.choice(all_chars)
print("\n\tGenerated password : " ,password+"\n")
# asks user for regenerating/accepting/exiting from the app
def rep():
print("""\t1.ACCEPT\n\t2.REGENERATE\n\t3.EXIT""")
return input("\n\tEnter your choice : ")
# main function
main()