0

I've been assigned a piece of homework to add a tkinter GUI to normal python code.
This is my code:

from tkinter import *
Window = Tk()
PasswordActual = Entry(Window)
Password = str(PasswordActual)
L1 = Label(Window, text = "Enter password:")
L2 = Label(Window)
def Main():
    PasswordCheck1 = len(Password)
    NumbersList = []
    CapsList = []
    LowersList = []
    def PasswordProcesser(WhatCharacters, CharactersInPassword):
        for Characters in WhatCharacters:
            if Characters in Password:
                PasswordCheck2 = Characters in Password
                if CharactersInPassword == "Numbers":
                    NumbersList.append(PasswordCheck2)
                elif CharactersInPassword == "Caps":
                    CapsList.append(PasswordCheck2)
                elif CharactersInPassword == "Lowers":
                    LowersList.append(PasswordCheck2)
    if PasswordCheck1 >= 6 and PasswordCheck1 <= 12:
        PasswordProcesser(["1","2","3","4","5","6","7","8","9"], "Numbers")
        PasswordProcesser(["A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","Q","Y","Z"], "Caps")
        PasswordProcesser(["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"], "Lowers")
        NumbersInPassword = sum(NumbersList) 
        CapsInPassword = sum(CapsList)
        LowersInPassword = sum(LowersList)
        if NumbersInPassword == 0 and CapsInPassword == 0 and LowersInPassword > 0 or CapsInPassword == 0 and NumbersInPassword > 0 and LowersInPassword == 0 or LowersInPassword == 0 and CapsInPassword > 0 and NumbersInPassword == 0:
            L2.configure(text = "Password is weak")
        elif NumbersInPassword == 0 and CapsInPassword > 0 and LowersInPassword > 0 or CapsInPassword == 0 and LowersInPassword > 0 and NumbersInPassword > 0 or LowersInPassword == 0 and NumbersInPassword > 0 and CapsInPassword > 0:
            L2.configure(text = "Password is medium")
        else:
            L2.configure(text = "Password is strong")
    else:
        L2.configure(text = "Password too long or short")
Checker = Button(Window, text = "Check Password", command = Main)
L1.grid(row = 1, column = 1)
PasswordActual.grid(row = 1, column = 2)
Checker.grid(row = 2, column = 1)
L2.grid(row = 2, column = 2)

My desired output tells the user that his or her code is weak, medium or strong. It works without the added tkinter stuff but it repeatedly tells me that my password is weak. Is there any reason for this, or am I just being stupid? (I'm a tkinter beginner) Thx in advance.
This is my (working) code without GUI:

def Main2():
    Password = input("What is your password?: ") 
    PasswordCheck1 = len(Password)
    NumbersList = []
    CapsList = []
    LowersList = []
    def ExitFunc():
        Exit = input("Do you want to exit or retry?: ")
        if Exit == "exit" or Exit == "Exit":
            exit
        elif Exit == "retry" or Exit == "Retry":
            Main2()
        else:
            print("Invalid input, enter exit or retry")
            ExitFunc()
    def PasswordProcesser(WhatCharacters, CharactersInPassword):
        for Characters in WhatCharacters:
            if Characters in Password:
                PasswordCheck2 = Characters in Password
                if CharactersInPassword == "Numbers":
                    NumbersList.append(PasswordCheck2)
                elif CharactersInPassword == "Caps":
                    CapsList.append(PasswordCheck2)
                elif CharactersInPassword == "Lowers":
                    LowersList.append(PasswordCheck2)
    if PasswordCheck1 >= 6 and PasswordCheck1 <= 12:
        PasswordProcesser(["1","2","3","4","5","6","7","8","9"], "Numbers")
        PasswordProcesser(["A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","Q","Y","Z"], "Caps")
        PasswordProcesser(["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"], "Lowers")
        NumbersInPassword = sum(NumbersList)
        CapsInPassword = sum(CapsList)
        LowersInPassword = sum(LowersList)
        if NumbersInPassword == 0 and CapsInPassword == 0 and LowersInPassword > 0 or CapsInPassword == 0 and NumbersInPassword > 0 and LowersInPassword == 0 or LowersInPassword == 0 and CapsInPassword > 0 and NumbersInPassword == 0:
            print("Password is weak, try and include capital, lowercase and numerical characters")
            ExitFunc()
        elif NumbersInPassword == 0 and CapsInPassword > 0 and LowersInPassword > 0 or CapsInPassword == 0 and LowersInPassword > 0 and NumbersInPassword > 0 or LowersInPassword == 0 and NumbersInPassword > 0 and CapsInPassword > 0:
            print("Password is medium, try and include capital, lowercase and numerical characters")
            ExitFunc()
        else:
            print("Password is strong")
            ExitFunc()
    else:
        print("Password too long or short, it needs to be no shorter than 6 and no longer than 12")
        ExitFunc()
Main2()
5
  • @Zetys I already know how to do that it's the GUI that's made the problems. Commented Jan 3, 2016 at 11:18
  • @MasterChief I'm still trying to solve this, the tkinter GUI seems fine... I've found there's problems in the validation section. Commented Jan 3, 2016 at 11:21
  • Try adding parenthesis to your conditions (or still better use a separate function to compute the password's strength...) Commented Jan 3, 2016 at 11:22
  • You are right, the problem is in GUI.Check my answer Commented Jan 3, 2016 at 11:35
  • Could you make a minimal, running example of your problem? Commented Jan 3, 2016 at 12:02

1 Answer 1

2

The problem is in password get.
You shoud get the password from Entry in Main function like this:

PasswordCheck1 = len(PasswordActual.get())

It is necessary to remove the third line Password = str(PasswordActual) because it is a reference to PasswordActual.

Look this:

from tkinter import *
Window = Tk()
PasswordActual = Entry(Window)
L1 = Label(Window, text = "Enter password:")
L2 = Label(Window)
def Main():
    Password = PasswordActual.get()
    PasswordCheck1 = len(Password)
    ..............................
Sign up to request clarification or add additional context in comments.

2 Comments

This makes the length restriction work but it still outputs password is weak no matter what.
I didn't realise you could do that, new to this

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.