简体   繁体   English

使用 tkinter 的 Python 密码更改程序

[英]Python Password Change program with tkinter

I am having trouble getting these checks to work.我无法让这些检查正常工作。 it is for a password change program using tkinter.它用于使用 tkinter 的密码更改程序。 The aim is to make sure the password has both capital and lowercase letters, and is more than 8 characters long.目的是确保密码既有大写字母又有小写字母,并且长度超过 8 个字符。 the code always outputs false, even when the password should pass all the checks.即使密码应该通过所有检查,代码也总是输出错误。

def check_password():
    global oldpassword_entry
    oldpasswordcheck= oldpassword_entry.get()
    global newpassword_entry
    newpasswordcheck= newpassword_entry.get()
    global newpasswordconfirmed_entry
    newpasswordconfirmedcheck= newpasswordconfirmed_entry.get()
    if oldpasswordcheck == oldpassword:
        if (any(x.isupper() for x in newpasswordcheck) and any(x.islower() for x in newpasswordcheck) and any(x.isdigit() for x in newpasswordcheck) and len(s) >= 8):    
            if newpasswordcheck == newpasswordconfirmedcheck:
                passwordtrue = 'true'
                print(passwordtrue)
                showoldpasswordchange_label.configure(text=newpasswordconfirmedcheck)
            else:
                passwordtrue = 'false'
                print(passwordtrue)
        else:
            passwordtrue = 'false'
            print(passwordtrue)
    else:
        passwordtrue = 'false'
        print(passwordtrue)
               
                

okaybutton_button = ttk.Button(root, text= "Okay", width= 20, command= check_password)

the variables at the start of the function come from the entries here:函数开头的变量来自这里的条目:

    showoldpassword_label = tk.Label(root, text = 'Current Password: ', font=('calibre',10, 'bold'))
    showoldpasswordchange_label = tk.Label(root, text = 'PasswordExample', font=('calibre',10, 'bold'))
    oldpassword_label = tk.Label(root, text = 'Old Password: ', font=('calibre',10, 'bold'))
    oldpassword_entry = tk.Entry(root, font=('calibre',10,'normal'), show = '*')
    newpassword_label = tk.Label(root, text = 'New Password: ', font=('calibre',10, 'bold'))
    newpassword_entry = tk.Entry(root, font=('calibre',10,'normal'), show = '*')
    newpasswordconfirmed_label = tk.Label(root, text = 'Confirm Password: ', font=('calibre',10, 'bold'))
    newpasswordconfirmed_entry = tk.Entry(root, font=('calibre',10,'normal'), show = '*')

when the code is run it makes this box:当代码运行时,它会生成这个框:

tkinterwindowwithlabelsandstuff

What is s in if (any(x.isupper() for x in newpasswordcheck) and any(x.islower() for x in newpasswordcheck) and any(x.isdigit() for x in newpasswordcheck) and len(s) >= 8): if (any( s if (any(x.isupper() for x in newpasswordcheck) and any(x.islower() for x in newpasswordcheck) and any(x.isdigit() for x in newpasswordcheck) and len(s) >= 8):

Maybe just swap s for newpasswordcheck ?也许只是将s换成newpasswordcheck

The code otherwise looks right to me, i havn't tried it though just read it and im missing s and oldpassword which i'm guessing is the current password as a string?否则代码看起来对我来说是正确的,我没有尝试过,虽然只是阅读它并且我缺少soldpassword我猜是当前密码作为字符串?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM