I am attempting to implement a simple password checker which will allow the user to open a text file that contains generated passwords and check them against a list of criteria to see if the password is strong or weak. It should then output the password with the result of whether it is strong or weak.
With the current solution I can get the list of passwords to print, but when the check as to whether the password is strong or not, only one result is shown. I am attempting for the output to be the password that is generated with the result e.g. Randompassword123 - This is a weak password.
Below is the code I am currently using:
def multiplestrength(): # password strength check function
textfile = filedialog.askopenfilename(initialdir="/home", title = "Select text file to split",filetypes = (("text files","*.txt"),("all files","*.*")))
with open(textfile , mode="r",encoding="utf-8") as my_file:
data=my_file.read()
print(data)
def strongPassword(data):
if passRegex1.search(data) == None:
return False
if passRegex2.search(data) == None:
return False
if passRegex3.search(data) == None:
return False
if passRegex4.search(data) == None:
return False
else:
return True
passRegex1 = re.compile(r'\w{8,}')
passRegex2 = re.compile(r'\d+')
passRegex3 = re.compile(r'[a-z]')
passRegex4 = re.compile(r'[A-Z]')
if strongPassword(data) == True:
print("Strong Password")
else:
print("This is not a strong password")
The output I receive is below
So it appears that only one password is being checked from the list of 5 passwords in the text file. I believe there might need to be a for loop required somewhere for each password to be checked, but I am unsure what way to approach this. Another approach I was thinking would be to insert the passwords from the text file into a list and iterating through this list to get a result for each password. Does this possibly sound like the correct way to approach this?
Any help with this would be greatly appreciated.
Thanks
