Skip to content

Commit d4f8cff

Browse files
authored
Merge pull request #146 from SSHSRN/passwordGenerator
added password generator
2 parents d03bb89 + 34e6fa7 commit d4f8cff

File tree

6 files changed

+148
-0
lines changed

6 files changed

+148
-0
lines changed

Password Generator/README.md

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
**PASSWORD GENERATOR**
2+
3+
**GOAL**
4+
This is a simple password generator created in python programming language. You can generate a password of any length and with any number of characters.
5+
6+
**DESCRIPTION**
7+
The goal is to create a password of any length and with any number of characters based on the user's input.
8+
9+
To use this code download passwordGenerator.py and resources in the same directory.
10+
+ Open and run the file passwordGenerator.py
11+
+ enjoy the code :-D
12+
13+
To use the GUI version of this code, download passwordGeneratorGUI.py and resources in the same directory.
14+
+ Open and run the file passwordGeneratorGUI.py
15+
+ enjoy the code :-D
16+
17+
**WHAT I HAD DONE**
18+
In this code, I implemented the code by using the following concepts:
19+
+ Tkinter module
20+
+ random module
21+
22+
**DEMONSTRATION**
23+
![image](./images/cmd.png)
24+
![image](./images/gui.png)
25+
![image](./images/gui2.png)
26+
27+
I wish you enjoy guess this code :-D
28+
29+
**SRIHARI S**

Password Generator/images/cmd.png

51.6 KB
Loading

Password Generator/images/gui.png

53 KB
Loading

Password Generator/images/gui2.png

68.2 KB
Loading
+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import random
2+
3+
def passwordGenerator():
4+
print("""
5+
Password Generator
6+
------------------
7+
For yes or no questions, enter 'y' or 'n' respectively. (Case insensitive)
8+
""")
9+
length = int(input("Enter the length of password: "))
10+
ch = input("Do you want to include special characters? (y/n): ")
11+
lowerAlphabets = input("Do you want to include lower case alphabets? (y/n): ")
12+
upperAlphabets = input("Do you want to include upper case alphabets? (y/n): ")
13+
numbers = input("Do you want to include numbers? (y/n): ")
14+
password = ""
15+
16+
if length == 0:
17+
print("Please enter a valid length.")
18+
return
19+
20+
if((ch != 'y' and ch != 'Y' and ch != 'n' and ch != 'N') or (lowerAlphabets != 'y' and lowerAlphabets != 'Y' and lowerAlphabets != 'n' and lowerAlphabets != 'N') or (upperAlphabets != 'y' and upperAlphabets != 'Y' and upperAlphabets != 'n' and upperAlphabets != 'N') or (numbers != 'y' and numbers != 'Y' and numbers != 'n' and numbers != 'N') or (length == 0)):
21+
print("Please enter 'y' or 'n' for yes or no questions respectively.")
22+
return
23+
24+
if ch == 'y' or ch == 'Y':
25+
password += "!@#$%^&*()_+"
26+
if lowerAlphabets == 'y' or lowerAlphabets == 'Y':
27+
password += "abcdefghijklmnopqrstuvwxyz"
28+
if upperAlphabets == 'y' or upperAlphabets == 'Y':
29+
password += "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
30+
if numbers == 'y' or numbers == 'Y':
31+
password += "0123456789"
32+
33+
print("Your password is: ", end="")
34+
for i in range(length):
35+
print(random.choice(password), end="")
36+
print()
37+
38+
passwordGenerator()
+81
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
import random
2+
import tkinter as tk
3+
from tkinter import messagebox
4+
5+
def passwordGenerator():
6+
if(entry1.get() == "" or entry2.get() == "" or entry3.get() == "" or entry4.get() == "" or entry5.get() == ""):
7+
messagebox.showerror("Error", "Please fill all the fields.")
8+
return
9+
elif((entry2.get() != 'y' and entry2.get() != 'Y' and entry2.get() != 'n' and entry2.get() != 'N') or (entry3.get() != 'y' and entry3.get() != 'Y' and entry3.get() != 'n' and entry3.get() != 'N') or (entry4.get() != 'y' and entry4.get() != 'Y' and entry4.get() != 'n' and entry4.get() != 'N') or (entry5.get() != 'y' and entry5.get() != 'Y' and entry5.get() != 'n' and entry5.get() != 'N')):
10+
messagebox.showerror("Error", "Please enter 'y' or 'n' for yes or no questions respectively.")
11+
return
12+
13+
length = int(entry1.get())
14+
ch = entry2.get()
15+
lowerAlphabets = entry3.get()
16+
upperAlphabets = entry4.get()
17+
numbers = entry5.get()
18+
password = ""
19+
20+
if ch == 'y' or ch == 'Y':
21+
password += "!@#$%^&*()_+"
22+
if lowerAlphabets == 'y' or lowerAlphabets == 'Y':
23+
password += "abcdefghijklmnopqrstuvwxyz"
24+
if upperAlphabets == 'y' or upperAlphabets == 'Y':
25+
password += "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
26+
if numbers == 'y' or numbers == 'Y':
27+
password += "0123456789"
28+
29+
passwordGenerated = ""
30+
for i in range(length):
31+
passwordGenerated += random.choice(password)
32+
messagebox.showinfo("Password Generator", "Your password is: " + passwordGenerated)
33+
34+
window = tk.Tk()
35+
window.title("Password Generator")
36+
window.geometry("600x400")
37+
window.resizable(False, False)
38+
39+
label1 = tk.Label(window, text="Password Generator", font=("Arial", 20))
40+
label1.pack()
41+
42+
label2 = tk.Label(window, text="------------------", font=("Arial", 20))
43+
label2.pack()
44+
45+
label3 = tk.Label(window, text="For yes or no questions, enter 'y' or 'n' respectively. (Case insensitive)", font=("Arial", 10))
46+
label3.pack()
47+
48+
label4 = tk.Label(window, text="Enter the length of password: ", font=("Arial", 10))
49+
label4.pack()
50+
51+
entry1 = tk.Entry(window, width=10)
52+
entry1.pack()
53+
54+
label5 = tk.Label(window, text="Do you want to include special characters? (y/n): ", font=("Arial", 10))
55+
label5.pack()
56+
57+
entry2 = tk.Entry(window, width=10)
58+
entry2.pack()
59+
60+
label6 = tk.Label(window, text="Do you want to include lower case alphabets? (y/n): ", font=("Arial", 10))
61+
label6.pack()
62+
63+
entry3 = tk.Entry(window, width=10)
64+
entry3.pack()
65+
66+
label7 = tk.Label(window, text="Do you want to include upper case alphabets? (y/n): ", font=("Arial", 10))
67+
label7.pack()
68+
69+
entry4 = tk.Entry(window, width=10)
70+
entry4.pack()
71+
72+
label8 = tk.Label(window, text="Do you want to include numbers? (y/n): ", font=("Arial", 10))
73+
label8.pack()
74+
75+
entry5 = tk.Entry(window, width=10)
76+
entry5.pack()
77+
78+
button1 = tk.Button(window, text="Generate Password", command=passwordGenerator)
79+
button1.pack()
80+
81+
window.mainloop()

0 commit comments

Comments
 (0)