如何修复“ TypeError:guessPassword()缺少1个必需的位置参数:'real'”

时间:2019-04-24 14:16:27

标签: python tkinter

我正在处理一些代码,其中在tkinter中按下按钮时,将运行暴力脚本,直到脚本生成的字符串与在tkinter输入框中输入的字符串(rootEntry3)相同为止。通过使用passWord = input("what is your password")脚本可以正常工作,但是当我尝试将其添加到我已经编写的代码中时,将passWord更改为passWord = rootEntry3.get()时,出现此错误调用中的文件“ C:\ Users \ George \ AppData \ Local \ Programs \ Python \ Python37 \ lib \ tkinter__init __。py”,行1705     返回self.func(* args) TypeError:guessPassword()缺少1个必需的位置参数:“ real”。任何想法如何解决?我很沮丧


import hashlib
from tkinter import *
import itertools
import string
import tkinter.messagebox
loginState = False
correctPassHash = '5f4dcc3b5aa765d61d8327deb882cf99' #password is "password"
root = Tk()
root.withdraw()
root2 = Tk()
root3 = Tk()
root3.withdraw()

def guessPassword(real):
    root3Entry.get()
    passWord = root3Entry.get()
    chars = string.ascii_lowercase + string.digits
    attempts = 0
    for password_length in range(1,5):
        for guess in itertools.product(chars, repeat=password_length):
            attempts+= 1
            guess = ''.join(guess)
            if guess == real:
                return 'password is {}. found in {} guesses'.format(guess,attempts)
            print(guess,attempts)
print(guess_password(passWord))


def openNew():
    root3.update()
    root3.deiconify()

def hideWindow():
    root2.withdraw()
    openNew()

def passwordHash():
    entry2val = (entry_2.get()) ##reminder for next time youre working on this, passHash2 keeps outputting the same hash value no matter what value is used in the input box in the gui. this is cos its hashing a blank string therefore producing a hash of nothing
    passHash1 = hashlib.md5(entry2val.encode())
    passHash3 = passHash1.hexdigest()
    print(passHash3)
    if passHash3 == correctPassHash:
        loginState = True
        tkinter.messagebox.showinfo('Successful login','You are now logged in')
        entry_2.delete(0,END)
        hideWindow()
    else:

        tkinter.messagebox.showerror('Login Error','You have entered an incorrect password!')
        entry_2.delete(0,END)



root.geometry("400x200")

label_2 = Label(root2, text="Password")
entry_1 = Entry(root2)
entry_2 = Entry(root2)
root3Label = Label(root3,text="Enter Password to be Brute Forced")
root3Label.grid(row=0,column=0)
root3Entry = Entry(root3)
root3Entry.grid(row=0,column=1)
root3Button = Button(root3,text="Go",fg="black",bg="green",command = guessPassword)
root3Button.grid(row=1)
passWord = root3Entry.get()



label_2.grid(row=1,column=0)

entry_2.grid(row=1,column=1)


loginButton = Button(root2, text="Login",fg="black",command = passwordHash )
loginButton.grid(row=1,column=5)


root.mainloop()
##this is the original brute force script, this works fine. 

import itertools
import string
passWord = input("Enter string to brute force")
def guess_password(real):

    chars = string.ascii_lowercase + string.digits
    attempts = 0
    for password_length in range(1, 5):
        for guess in itertools.product(chars, repeat=password_length):
            attempts += 1
            guess = ''.join(guess)
            if guess == real:
                return 'password is {}. found in {} guesses.'.format(guess, attempts)
            print(guess, attempts)

print(guess_password(passWord))

我希望函数guessPassword()使用root3Entry的输入,然后输出与原始脚本相同的输出。

0 个答案:

没有答案