我找到了一种使用python检查用户密码的方法。如果我输入了错误的密码,它将返回:“ password错误”,并使用正确的密码将给出:“ password正确”,并将密码写入文件。
我为没有密码的用户尝试过此操作。如果我不提供密码或空字符串,它仍然会返回“密码错误”。有办法解决这个问题吗?
这是我的代码:
try:
win32security.LogonUser(
username,
domain,
password,
win32security.LOGON32_LOGON_NETWORK,
win32security.LOGON32_PROVIDER_DEFAULT
)
except win32security.error:
tkinter.messagebox.showerror("Title", "Password wrong!")
else:
user_password_file = open("password.txt", "a")
if password not in open(filename1).read():
user_password_file.write(username + ":" + password + "\n")
tkinter.messagebox.showinfo("Title", "Password correct")
对于用户名,我将其用于gui:
self.selected_user_var = tkinter.StringVar()
self.selected_user_var.set(user_list[0])
self.select_user_macos = tkinter.OptionMenu(self.user_tools, self.selected_user_var, *user_list)
self.select_user_macos.grid(row=1, column=3, padx=5, sticky=tkinter.W, pady=5)
列表中填充了以下用户名:
server = None
level = 0
filter_win32 = win32netcon.FILTER_NORMAL_ACCOUNT
resume_handle = 0
user_list = []
while True:
result = win32net.NetUserEnum(server, level, filter_win32, resume_handle)
user_list += [user['name'] for user in result[0]]
resume_handle = result[2]
if not resume_handle:
break
user_list.sort()
对于密码,我使用一个简单的条目:
self.entry_user_password = tkinter.Entry(self.user_tools, width=30, bd=1,
textvariable=self.var_user_password)
self.entry_user_password.grid(row=2, column=3, padx=5, sticky=tkinter.W, pady=5)