Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update password_generator.py #376

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
71 changes: 71 additions & 0 deletions GUI/Password Generator/password_generator.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,22 @@
from tkinter import *
from tkinter.ttk import *
import tkinter as tk
from PIL import Image, ImageTk
import random
import string
import pyperclip
import re

crack_speed = 400000000000
format = {'Uppercase characters': 0,
'Lowercase characters': 0,
'Special characters': 0,
'Numbers': 0}

entropies = {'Uppercase characters': 26,
'Lowercase characters': 26,
'Special characters': 33,
'Numbers': 10}

# Define the main function for generating the password
def generate_password():
Expand All @@ -10,6 +25,8 @@ def generate_password():
password = ''.join(random.choices(string.ascii_letters + string.digits + string.punctuation, k=int(password_length)))
password_entry.delete(0, tk.END)
password_entry.insert(0, password)
password_ckeck = password_strength(password)
passwordStrength.config(text=password_ckeck)
else:
password_entry.delete(0, tk.END)
password_entry.insert(0, "Invalid password length")
Expand All @@ -19,8 +36,59 @@ def copy_password():
password = password_entry.get()
pyperclip.copy(password)

#Define the function to ckeck the password strength
def password_strength(password):
password_len = len(password)
if(len(password) < 7):
strength = "very weak"
else:
if( len(password) < 9 ):
strength = "weak"
else:
if(len(password) < 11):
strength = "good"
else:
strength = "strong"
for char in password:
if re.match("[0-9]", char):
format["Numbers"] += 1
elif re.match("[a-z]", char):
format["Lowercase characters"] += 1
elif re.match("[A-Z]", char):
format["Uppercase characters"] += 1
else:
format["Special characters"] += 1
entropy = 0
for frm in format.keys():
if format[frm] > 0:
entropy += entropies[frm]

time_ = "hours"
cracked = ((entropy**password_len) / crack_speed) / 3600 # Hours in seconds

if cracked > 24:
cracked = cracked / 24
time_ = "days"

if cracked > 365:
cracked = cracked / 365
time_ = "years"

if time_ == "years" and cracked > 100:
cracked = cracked / 100
time_ = "centuries"

if time_ == "centuries" and cracked > 1000:
cracked = cracked / 1000
time_ = "millennia"
cracked = "\nTime to crack password: {:,.2f} {}".format(cracked, time_)
text = strength + cracked
return text


# Create the main window
root = tk.Tk()
root.geometry("350x350")
root.title("Password Generator")

# Create the password length label and entry widget
Expand All @@ -39,6 +107,9 @@ def copy_password():
password_entry = tk.Entry(root, width=30)
password_entry.pack(pady=10)

passwordStrength = tk.Label(root, text = "")
passwordStrength.pack()

# Create the "Copy Password" button
copy_button = tk.Button(root, text="Copy Password", command=copy_password)
copy_button.pack(pady=10)
Expand Down
Loading