mirror of
https://github.com/metafy-social/python-scripts.git
synced 2024-11-24 04:21:12 +00:00
Merge pull request #15 from Montekkundan/master
🚀 Added CLI and GUI password generator.
This commit is contained in:
commit
d20ad9e223
37
.idea/inspectionProfiles/Project_Default.xml
Normal file
37
.idea/inspectionProfiles/Project_Default.xml
Normal file
|
@ -0,0 +1,37 @@
|
||||||
|
<component name="InspectionProjectProfileManager">
|
||||||
|
<profile version="1.0">
|
||||||
|
<option name="myName" value="Project Default" />
|
||||||
|
<inspection_tool class="PyPackageRequirementsInspection" enabled="true" level="WARNING" enabled_by_default="true">
|
||||||
|
<option name="ignoredPackages">
|
||||||
|
<value>
|
||||||
|
<list size="1">
|
||||||
|
<item index="0" class="java.lang.String" itemvalue="jupyter" />
|
||||||
|
</list>
|
||||||
|
</value>
|
||||||
|
</option>
|
||||||
|
</inspection_tool>
|
||||||
|
<inspection_tool class="PyPep8Inspection" enabled="true" level="WEAK WARNING" enabled_by_default="true">
|
||||||
|
<option name="ignoredErrors">
|
||||||
|
<list>
|
||||||
|
<option value="E501" />
|
||||||
|
</list>
|
||||||
|
</option>
|
||||||
|
</inspection_tool>
|
||||||
|
<inspection_tool class="PyPep8NamingInspection" enabled="true" level="WEAK WARNING" enabled_by_default="true">
|
||||||
|
<option name="ignoredErrors">
|
||||||
|
<list>
|
||||||
|
<option value="N813" />
|
||||||
|
<option value="N802" />
|
||||||
|
<option value="N806" />
|
||||||
|
</list>
|
||||||
|
</option>
|
||||||
|
</inspection_tool>
|
||||||
|
<inspection_tool class="PyUnresolvedReferencesInspection" enabled="true" level="WARNING" enabled_by_default="true">
|
||||||
|
<option name="ignoredIdentifiers">
|
||||||
|
<list>
|
||||||
|
<option value="str.sleep" />
|
||||||
|
</list>
|
||||||
|
</option>
|
||||||
|
</inspection_tool>
|
||||||
|
</profile>
|
||||||
|
</component>
|
6
.idea/inspectionProfiles/profiles_settings.xml
Normal file
6
.idea/inspectionProfiles/profiles_settings.xml
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
<component name="InspectionProjectProfileManager">
|
||||||
|
<settings>
|
||||||
|
<option name="USE_PROJECT_PROFILE" value="false" />
|
||||||
|
<version value="1.0" />
|
||||||
|
</settings>
|
||||||
|
</component>
|
4
.idea/misc.xml
Normal file
4
.idea/misc.xml
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.10 (Teapot.py)" project-jdk-type="Python SDK" />
|
||||||
|
</project>
|
8
.idea/modules.xml
Normal file
8
.idea/modules.xml
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="ProjectModuleManager">
|
||||||
|
<modules>
|
||||||
|
<module fileurl="file://$PROJECT_DIR$/.idea/daily-python-scripts.iml" filepath="$PROJECT_DIR$/.idea/daily-python-scripts.iml" />
|
||||||
|
</modules>
|
||||||
|
</component>
|
||||||
|
</project>
|
6
.idea/vcs.xml
Normal file
6
.idea/vcs.xml
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="VcsDirectoryMappings">
|
||||||
|
<mapping directory="$PROJECT_DIR$" vcs="Git" />
|
||||||
|
</component>
|
||||||
|
</project>
|
50
.idea/workspace.xml
Normal file
50
.idea/workspace.xml
Normal file
|
@ -0,0 +1,50 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="ChangeListManager">
|
||||||
|
<list default="true" id="30485b52-3e0f-4735-a0c9-e97f9f8a9b19" name="Changes" comment="" />
|
||||||
|
<option name="SHOW_DIALOG" value="false" />
|
||||||
|
<option name="HIGHLIGHT_CONFLICTS" value="true" />
|
||||||
|
<option name="HIGHLIGHT_NON_ACTIVE_CHANGELIST" value="false" />
|
||||||
|
<option name="LAST_RESOLUTION" value="IGNORE" />
|
||||||
|
</component>
|
||||||
|
<component name="Git.Settings">
|
||||||
|
<option name="RECENT_GIT_ROOT_PATH" value="$PROJECT_DIR$" />
|
||||||
|
</component>
|
||||||
|
<component name="MarkdownSettingsMigration">
|
||||||
|
<option name="stateVersion" value="1" />
|
||||||
|
</component>
|
||||||
|
<component name="ProjectId" id="2FIEGVlNIQ4EN0SrASbvicYSJcX" />
|
||||||
|
<component name="ProjectLevelVcsManager" settingsEditedManually="true" />
|
||||||
|
<component name="ProjectViewState">
|
||||||
|
<option name="hideEmptyMiddlePackages" value="true" />
|
||||||
|
<option name="showLibraryContents" value="true" />
|
||||||
|
</component>
|
||||||
|
<component name="PropertiesComponent"><![CDATA[{
|
||||||
|
"keyToString": {
|
||||||
|
"RunOnceActivity.OpenProjectViewOnStart": "true",
|
||||||
|
"RunOnceActivity.ShowReadmeOnStart": "true"
|
||||||
|
}
|
||||||
|
}]]></component>
|
||||||
|
<component name="SpellCheckerSettings" RuntimeDictionaries="0" Folders="0" CustomDictionaries="0" DefaultDictionary="application-level" UseSingleDictionary="true" transferred="true" />
|
||||||
|
<component name="TaskManager">
|
||||||
|
<task active="true" id="Default" summary="Default task">
|
||||||
|
<changelist id="30485b52-3e0f-4735-a0c9-e97f9f8a9b19" name="Changes" comment="" />
|
||||||
|
<created>1664171102669</created>
|
||||||
|
<option name="number" value="Default" />
|
||||||
|
<option name="presentableId" value="Default" />
|
||||||
|
<updated>1664171102669</updated>
|
||||||
|
</task>
|
||||||
|
<servers />
|
||||||
|
</component>
|
||||||
|
<component name="Vcs.Log.Tabs.Properties">
|
||||||
|
<option name="TAB_STATES">
|
||||||
|
<map>
|
||||||
|
<entry key="MAIN">
|
||||||
|
<value>
|
||||||
|
<State />
|
||||||
|
</value>
|
||||||
|
</entry>
|
||||||
|
</map>
|
||||||
|
</option>
|
||||||
|
</component>
|
||||||
|
</project>
|
60
scripts/Password Generator/CLI/CLI.py
Normal file
60
scripts/Password Generator/CLI/CLI.py
Normal file
|
@ -0,0 +1,60 @@
|
||||||
|
from random import choice, shuffle
|
||||||
|
|
||||||
|
|
||||||
|
def generate_password(user_letters, user_numbers, user_symbols):
|
||||||
|
"""
|
||||||
|
Generates a random password.
|
||||||
|
|
||||||
|
Parameters
|
||||||
|
----------
|
||||||
|
:param user_letters: Number of letters to generate in the password.
|
||||||
|
:param user_numbers: Number of numbers to generate in the password.
|
||||||
|
:param user_symbols: Number of symbols to generate in the password.
|
||||||
|
|
||||||
|
:return: Password as a string.
|
||||||
|
"""
|
||||||
|
letters = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u',
|
||||||
|
'v',
|
||||||
|
'w', 'x', 'y', 'z', 'A', 'B',
|
||||||
|
'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W',
|
||||||
|
'X',
|
||||||
|
'Y', 'Z']
|
||||||
|
numbers = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9']
|
||||||
|
symbols = ['!', '#', '$', '%', '&', '(', ')', '*', '+']
|
||||||
|
|
||||||
|
p_letters = [choice(letters) for _ in range(0, user_letters)]
|
||||||
|
p_symbols = [choice(symbols) for _ in range(0, user_symbols)]
|
||||||
|
p_numbers = [choice(numbers) for _ in range(0, user_numbers)]
|
||||||
|
pwd = p_letters + p_symbols + p_numbers
|
||||||
|
shuffle(pwd)
|
||||||
|
|
||||||
|
password = "".join(pwd)
|
||||||
|
return password
|
||||||
|
|
||||||
|
|
||||||
|
with open("save.txt", "a") as file:
|
||||||
|
input_letters = int(input("How many letters do you want?\n"))
|
||||||
|
input_symbols = int(input("How many symbols do you want?\n"))
|
||||||
|
input_number = int(input("How many numbers do you want?\n"))
|
||||||
|
# checks if users enters all inputs as 0.
|
||||||
|
if input_letters != 0 and input_symbols != 0 and input_number != 0:
|
||||||
|
user_password = generate_password(input_letters, input_symbols, input_number)
|
||||||
|
print(f"Your password is: {user_password}")
|
||||||
|
user_choice = input("Do you want to save it? y for yes and n for no.\n")
|
||||||
|
correct_choice = False
|
||||||
|
while not correct_choice:
|
||||||
|
if user_choice == "y":
|
||||||
|
print("Saving...")
|
||||||
|
# saves the password in save.txt
|
||||||
|
file.write(f"{user_password}\n")
|
||||||
|
print("Saved...")
|
||||||
|
correct_choice = True
|
||||||
|
elif user_choice == "n":
|
||||||
|
print("Exiting...")
|
||||||
|
correct_choice = True
|
||||||
|
else:
|
||||||
|
print("Wrong input...")
|
||||||
|
# continues to ask whether to save the password or not.
|
||||||
|
user_choice = input("Do you want to save it? y for yes and n for no.\n")
|
||||||
|
else:
|
||||||
|
print("No password generated...")
|
3
scripts/Password Generator/CLI/save.txt
Normal file
3
scripts/Password Generator/CLI/save.txt
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
55mCD#$6*7*9TH+
|
||||||
|
)2S5$xIy43(+*g1
|
||||||
|
|
133
scripts/Password Generator/GUI/GUI.py
Normal file
133
scripts/Password Generator/GUI/GUI.py
Normal file
|
@ -0,0 +1,133 @@
|
||||||
|
from tkinter import *
|
||||||
|
from tkinter import messagebox
|
||||||
|
from random import choice, randint, shuffle
|
||||||
|
import pyperclip
|
||||||
|
import json
|
||||||
|
|
||||||
|
|
||||||
|
# ---------------------------- PASSWORD GENERATOR ------------------------------- #
|
||||||
|
def generate_password():
|
||||||
|
"""
|
||||||
|
Generates a random password, with 8-10 letters, 2-4 symbols and 2-4 numbers.
|
||||||
|
:return: Password as a string.
|
||||||
|
"""
|
||||||
|
password_entry.delete(0, END)
|
||||||
|
letters = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u',
|
||||||
|
'v',
|
||||||
|
'w', 'x', 'y', 'z', 'A', 'B',
|
||||||
|
'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W',
|
||||||
|
'X',
|
||||||
|
'Y', 'Z']
|
||||||
|
numbers = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9']
|
||||||
|
symbols = ['!', '#', '$', '%', '&', '(', ')', '*', '+']
|
||||||
|
|
||||||
|
p_letters = [choice(letters) for _ in range(randint(8, 10))]
|
||||||
|
p_symbols = [choice(symbols) for _ in range(randint(2, 4))]
|
||||||
|
p_numbers = [choice(numbers) for _ in range(randint(2, 4))]
|
||||||
|
pwd = p_letters + p_symbols + p_numbers
|
||||||
|
shuffle(pwd)
|
||||||
|
|
||||||
|
password = "".join(pwd)
|
||||||
|
password_entry.insert(0, password)
|
||||||
|
pyperclip.copy(password)
|
||||||
|
|
||||||
|
|
||||||
|
# ---------------------------- SAVE PASSWORD ------------------------------- #
|
||||||
|
def save():
|
||||||
|
website = website_entry.get()
|
||||||
|
email = email_entry.get()
|
||||||
|
password = password_entry.get()
|
||||||
|
new_data = {
|
||||||
|
website: {
|
||||||
|
"email": email,
|
||||||
|
"password": password,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(website) == 0 or len(password) == 0:
|
||||||
|
messagebox.showerror(title="Oops!", message="Please make sure you haven't left any fields empty.")
|
||||||
|
|
||||||
|
else:
|
||||||
|
ok_user = messagebox.askokcancel(title=website, message=f"These are the details entered:\nEmail: {email}"
|
||||||
|
f"\nPassword: {password} \nIs it okay to save?")
|
||||||
|
if ok_user:
|
||||||
|
try:
|
||||||
|
with open("data.json", "r") as data_file:
|
||||||
|
# Reading old data
|
||||||
|
data = json.load(data_file)
|
||||||
|
except FileNotFoundError:
|
||||||
|
with open("data.json", "w") as data_file:
|
||||||
|
json.dump(new_data, data_file, indent=4)
|
||||||
|
except json.JSONDecodeError:
|
||||||
|
data = dict()
|
||||||
|
|
||||||
|
else:
|
||||||
|
# Updating old data with new data
|
||||||
|
data.update(new_data)
|
||||||
|
|
||||||
|
with open("data.json", "w") as data_file:
|
||||||
|
# Saving updated data
|
||||||
|
json.dump(data, data_file, indent=4)
|
||||||
|
|
||||||
|
finally:
|
||||||
|
website_entry.delete(0, END)
|
||||||
|
password_entry.delete(0, END)
|
||||||
|
|
||||||
|
|
||||||
|
# ---------------------------- SEARCH PASSWORD ------------------------------- #
|
||||||
|
def search_password():
|
||||||
|
website = website_entry.get()
|
||||||
|
password= password_entry.get()
|
||||||
|
if len(website) == 0:
|
||||||
|
messagebox.showerror(title="Oops!", message="Please make sure you haven't left any fields empty.")
|
||||||
|
else:
|
||||||
|
try:
|
||||||
|
with open("data.json") as data_file:
|
||||||
|
data = json.load(data_file)
|
||||||
|
except FileNotFoundError:
|
||||||
|
messagebox.showerror(title="Error!", message="No data file found" )
|
||||||
|
else:
|
||||||
|
if website in data:
|
||||||
|
email = data[website]["email"]
|
||||||
|
password = data[website]["password"]
|
||||||
|
messagebox.showinfo(title=website, message=f"Email: {email} \nPassword: {password}")
|
||||||
|
else:
|
||||||
|
messagebox.showerror(title="Error!", message=f"No details for {website} exists.")
|
||||||
|
|
||||||
|
# ---------------------------- UI SETUP ------------------------------- #
|
||||||
|
window = Tk()
|
||||||
|
window.title("Password Manager")
|
||||||
|
window.config(padx=50, pady=50)
|
||||||
|
|
||||||
|
canvas = Canvas(width=220, height=220, highlightthickness=0)
|
||||||
|
logo_img = PhotoImage(file="GUI/logo.png")
|
||||||
|
canvas.create_image(100, 100, image=logo_img)
|
||||||
|
canvas.grid(column=1, row=0)
|
||||||
|
|
||||||
|
# Labels
|
||||||
|
website_label = Label(text="Website:")
|
||||||
|
website_label.grid(column=0, row=1)
|
||||||
|
email_label = Label(text="Email/Username:")
|
||||||
|
email_label.grid(column=0, row=2)
|
||||||
|
password_label = Label(text="Password:")
|
||||||
|
password_label.grid(column=0, row=3)
|
||||||
|
|
||||||
|
# Enteries
|
||||||
|
website_entry = Entry(width=23)
|
||||||
|
website_entry.grid(column=1, row=1)
|
||||||
|
website_entry.focus()
|
||||||
|
email_entry = Entry(width=40)
|
||||||
|
email_entry.grid(column=1, row=2, columnspan=2)
|
||||||
|
email_entry.insert(0, "hello@iamMontek.com")
|
||||||
|
password_entry = Entry(width=23)
|
||||||
|
password_entry.grid(column=1, row=3)
|
||||||
|
|
||||||
|
# Buttons
|
||||||
|
search_button = Button(text="Search", width=12, command=search_password)
|
||||||
|
search_button.grid(column=2, row=1)
|
||||||
|
generate_password_button = Button(text="Generate Password", command=generate_password)
|
||||||
|
generate_password_button.grid(column=2, row=3)
|
||||||
|
add_button = Button(text="Add", width=30, command=save)
|
||||||
|
add_button.grid(column=1, row=4, columnspan=2)
|
||||||
|
|
||||||
|
window.mainloop()
|
10
scripts/Password Generator/GUI/data.json
Normal file
10
scripts/Password Generator/GUI/data.json
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
{
|
||||||
|
"sample": {
|
||||||
|
"email": "sample@sample.com",
|
||||||
|
"password": ")x9E)pGiz74(wFm"
|
||||||
|
},
|
||||||
|
"sample2": {
|
||||||
|
"email": "hello@iamMontek.com",
|
||||||
|
"password": "6!69c)fXgiT1imK)*m"
|
||||||
|
}
|
||||||
|
}
|
BIN
scripts/Password Generator/GUI/logo.png
Normal file
BIN
scripts/Password Generator/GUI/logo.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 4.8 KiB |
10
scripts/Password Generator/README.md
Normal file
10
scripts/Password Generator/README.md
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
# Password Generator
|
||||||
|
|
||||||
|
## About
|
||||||
|
A Python3 script to generate a strong password.
|
||||||
|
### CLI
|
||||||
|
![](assets/img_1.png)
|
||||||
|
### GUI
|
||||||
|
![](assets/img.png)
|
||||||
|
|
||||||
|
![](assets/Untitled.gif)
|
BIN
scripts/Password Generator/assets/Untitled.gif
Normal file
BIN
scripts/Password Generator/assets/Untitled.gif
Normal file
Binary file not shown.
After Width: | Height: | Size: 5.3 MiB |
BIN
scripts/Password Generator/assets/img.png
Normal file
BIN
scripts/Password Generator/assets/img.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 24 KiB |
BIN
scripts/Password Generator/assets/img_1.png
Normal file
BIN
scripts/Password Generator/assets/img_1.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 34 KiB |
2
scripts/Password Generator/save.txt
Normal file
2
scripts/Password Generator/save.txt
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
Q1!7F%ju4r$(3!9
|
||||||
|
Vp*6f35!)!o0%q1
|
Loading…
Reference in New Issue
Block a user