1
+ from tkinter import *
2
+ from tkinter .ttk import *
1
3
import tkinter as tk
4
+ from PIL import Image , ImageTk
2
5
import random
3
6
import string
4
7
import pyperclip
8
+ import re
9
+
10
+ crack_speed = 400000000000
11
+ format = {'Uppercase characters' : 0 ,
12
+ 'Lowercase characters' : 0 ,
13
+ 'Special characters' : 0 ,
14
+ 'Numbers' : 0 }
15
+
16
+ entropies = {'Uppercase characters' : 26 ,
17
+ 'Lowercase characters' : 26 ,
18
+ 'Special characters' : 33 ,
19
+ 'Numbers' : 10 }
5
20
6
21
# Define the main function for generating the password
7
22
def generate_password ():
@@ -10,6 +25,8 @@ def generate_password():
10
25
password = '' .join (random .choices (string .ascii_letters + string .digits + string .punctuation , k = int (password_length )))
11
26
password_entry .delete (0 , tk .END )
12
27
password_entry .insert (0 , password )
28
+ password_ckeck = password_strength (password )
29
+ passwordStrength .config (text = password_ckeck )
13
30
else :
14
31
password_entry .delete (0 , tk .END )
15
32
password_entry .insert (0 , "Invalid password length" )
@@ -19,8 +36,59 @@ def copy_password():
19
36
password = password_entry .get ()
20
37
pyperclip .copy (password )
21
38
39
+ #Define the function to ckeck the password strength
40
+ def password_strength (password ):
41
+ password_len = len (password )
42
+ if (len (password ) < 7 ):
43
+ strength = "very weak"
44
+ else :
45
+ if ( len (password ) < 9 ):
46
+ strength = "weak"
47
+ else :
48
+ if (len (password ) < 11 ):
49
+ strength = "good"
50
+ else :
51
+ strength = "strong"
52
+ for char in password :
53
+ if re .match ("[0-9]" , char ):
54
+ format ["Numbers" ] += 1
55
+ elif re .match ("[a-z]" , char ):
56
+ format ["Lowercase characters" ] += 1
57
+ elif re .match ("[A-Z]" , char ):
58
+ format ["Uppercase characters" ] += 1
59
+ else :
60
+ format ["Special characters" ] += 1
61
+ entropy = 0
62
+ for frm in format .keys ():
63
+ if format [frm ] > 0 :
64
+ entropy += entropies [frm ]
65
+
66
+ time_ = "hours"
67
+ cracked = ((entropy ** password_len ) / crack_speed ) / 3600 # Hours in seconds
68
+
69
+ if cracked > 24 :
70
+ cracked = cracked / 24
71
+ time_ = "days"
72
+
73
+ if cracked > 365 :
74
+ cracked = cracked / 365
75
+ time_ = "years"
76
+
77
+ if time_ == "years" and cracked > 100 :
78
+ cracked = cracked / 100
79
+ time_ = "centuries"
80
+
81
+ if time_ == "centuries" and cracked > 1000 :
82
+ cracked = cracked / 1000
83
+ time_ = "millennia"
84
+ cracked = "\n Time to crack password: {:,.2f} {}" .format (cracked , time_ )
85
+ text = strength + cracked
86
+ return text
87
+
88
+
22
89
# Create the main window
23
90
root = tk .Tk ()
91
+ root .geometry ("350x350" )
24
92
root .title ("Password Generator" )
25
93
26
94
# Create the password length label and entry widget
@@ -39,6 +107,9 @@ def copy_password():
39
107
password_entry = tk .Entry (root , width = 30 )
40
108
password_entry .pack (pady = 10 )
41
109
110
+ passwordStrength = tk .Label (root , text = "" )
111
+ passwordStrength .pack ()
112
+
42
113
# Create the "Copy Password" button
43
114
copy_button = tk .Button (root , text = "Copy Password" , command = copy_password )
44
115
copy_button .pack (pady = 10 )
0 commit comments