I have found a way to check a users password with python. If i type in a wrong password it gives back: "password wrong" and with the right passwor it will give: "password correct" and writes the password to a file.
I tried this for a user without a password. If I don't give a password or an empty string it still return "wrong password". Is there a way to fix this?
This is my code:
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")
For the username I use this for my 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)
The list is filled with usernames with this:
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()
For the password I use a simple Entry:
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)