77for line in common_passwords_read :
88 modified_common_passwords .append (line .strip ()) # Places each of the 100,000 most commonly used passwords into a list
99
10- def check_password_strength (event , warnings , first_label , inputted_password , second_label , third_label , fourth_label ) -> None :
10+ def check_password_strength (event , inputted_password ) -> list :
1111 '''
1212 Called upon pressing the done button,
1313 this function hosts all functions necessary to check:
@@ -30,8 +30,6 @@ def check_password_strength(event, warnings, first_label, inputted_password, sec
3030 fourth_label: tkinter.Label()
3131 The fourth warning label.
3232 '''
33- for label in warnings :
34- label .configure (text = '' )
3533
3634 input = []
3735 input [:0 ] = inputted_password # Adds each character of the input to a list.
@@ -43,12 +41,10 @@ def check_if_password_is_common() -> None:
4341 checks if the inputted password is in the 100,000 most used passwords (modified_common_password).
4442 '''
4543 if modified_common_passwords .count (inputted_password ) > 0 :
46- first_label .configure (text = 'Common: Your password is common.' )
47- first_label .grid (column = 0 , row = 3 , sticky = 'w' )
44+ return 'Common: Your password is common.'
4845
4946 elif modified_common_passwords .count (inputted_password ) == 0 :
50- first_label .configure (text = 'Not common: Your password isn\' t common.' )
51- first_label .grid (column = 0 , row = 3 , sticky = 'w' )
47+ return 'Not common: Your password isn\' t common.'
5248
5349 def check_password_length () -> None :
5450 '''
@@ -57,24 +53,19 @@ def check_password_length() -> None:
5753 this function categorises the inputted password as very weak, weak, good, or strong depending on its length.
5854 '''
5955 if len (inputted_password ) == 1 :
60- second_label .configure (text = f'Very weak length: Your password has only { str (len (inputted_password ))} character.' )
61- second_label .grid (column = 0 , row = 4 , sticky = 'w' )
56+ return f'Very weak length: Your password has only { str (len (inputted_password ))} character.'
6257
6358 elif 0 < len (inputted_password ) <= 7 :
64- second_label .configure (text = f'Very weak length: Your password has only { str (len (inputted_password ))} characters.' )
65- second_label .grid (column = 0 , row = 4 , sticky = 'w' )
59+ return f'Very weak length: Your password has only { str (len (inputted_password ))} characters.'
6660
6761 elif 8 <= len (inputted_password ) <= 10 :
68- second_label .configure (text = f'Weak length: Your password has only { str (len (inputted_password ))} characters.' )
69- second_label .grid (column = 0 , row = 4 , sticky = 'w' )
62+ return f'Weak length: Your password has only { str (len (inputted_password ))} characters.'
7063
7164 elif 11 <= len (inputted_password ) <= 13 :
72- second_label .configure (text = f'Good length: Your password has { str (len (inputted_password ))} characters.' )
73- second_label .grid (column = 0 , row = 4 , sticky = 'w' )
65+ return f'Good length: Your password has { str (len (inputted_password ))} characters.'
7466
7567 elif 14 <= len (inputted_password ):
76- second_label .configure (text = f'Strong length: Your password has { str (len (inputted_password ))} characters.' )
77- second_label .grid (column = 0 , row = 4 , sticky = 'w' )
68+ return f'Strong length: Your password has { str (len (inputted_password ))} characters.'
7869
7970 def check_password_complexity () -> None :
8071 '''
@@ -134,12 +125,10 @@ def check_password_complexity() -> None:
134125 else :
135126 output = output + 'and ' + str (missing_feature )
136127
137- third_label .configure (text = f'Not complex: Your password is missing { output } .' )
138- third_label .grid (column = 0 , row = 5 , sticky = 'w' )
128+ return f'Not complex: Your password is missing { output } .'
139129
140130 else :
141- third_label .configure (text = 'Complex: Your password contains lowercase letters, uppercase letters, digits, and punctation.' )
142- third_label .grid (column = 0 , row = 5 , sticky = 'w' )
131+ return 'Complex: Your password contains lowercase letters, uppercase letters, digits, and punctation.'
143132
144133 def check_for_patterns_in_password () -> None :
145134 '''
@@ -151,16 +140,6 @@ def check_for_patterns_in_password() -> None:
151140 global are_there_repeated_characters
152141 are_there_repeated_characters = False
153142
154- def show_repeated_pattern_warning () -> None :
155- '''
156- Called by the check_for_patterns_in_password_function
157- (upon pressing the done button),
158- this function warns the user if there are repeated characters in their password.
159- '''
160-
161- fourth_label .configure (text = 'Repeated character(s): Your password contains at least one repeated character.' )
162- fourth_label .grid (column = 0 , row = 6 , sticky = 'w' )
163-
164143 for character in input : # For every character in the input, it checks if there is another character that matches, and shows the repeated pattern warning if there is.
165144 count = 0
166145 for other_character in input :
@@ -169,17 +148,17 @@ def show_repeated_pattern_warning() -> None:
169148
170149 if count > 1 :
171150 are_there_repeated_characters = True
172- show_repeated_pattern_warning ()
151+ return 'Repeated character(s): Your password contains at least one repeated character.'
173152
174153 if are_there_repeated_characters == False :
175- fourth_label .configure (text = 'No repeated characters: Your password contains no repeated characters.' )
176- fourth_label .grid (column = 0 , row = 6 , sticky = 'w' )
154+ return 'No repeated characters: Your password contains no repeated characters.'
177155
178156 if len (inputted_password ) == 0 :
179- first_label .configure (text = 'Please input a password.' )
180- first_label .grid (column = 0 , row = 3 , sticky = 'n' )
157+ return 'Please input a password.'
181158 else :
182- check_if_password_is_common ()
183- check_password_length ()
184- check_password_complexity ()
185- check_for_patterns_in_password ()
159+ prevalance_warning = check_if_password_is_common ()
160+ length_warning = check_password_length ()
161+ complexity_warning = check_password_complexity ()
162+ pattern_warning = check_for_patterns_in_password ()
163+
164+ return [prevalance_warning , length_warning , complexity_warning , pattern_warning ]
0 commit comments