1
我正在尝试构建一个脚本,用于检查当前登录用户的本地帐户上的密码是否具有在Windows中不为空的密码。我需要将它作为安全合规性背景检查的一部分来运行;它会报告给Nagios服务器。我需要在Python中完成这项工作,但如果Python不这样做,我会向PowerShell开放。使用Python检查本地帐户是否有空白密码
因此,该脚本将需要检测:
- 在当前登录用户的用户名。
- 上述用户是否有空白密码。
- 如果密码不为空,则返回错误代码0,如果是,则返回错误代码2。
我被困在任何一段代码将允许我检查当前用户的密码是否是“”。我有一个布局,未经太多的装饰,看起来是这样的:
import os
import Tkinter
import tkMessageBox
from Tkinter import Tk, Toplevel
MyGui.update_idletasks()
MyGui.attributes('-topmost', True)
MyGui.geometry('{}x{}'.format(300, 150))
MyGui.resizable(width=False, height=False)
MyGui.withdraw()
ThisUser = os.getlogin()
ThisPassword = ... # line of code necessary to test for blank password; this is the part where I'm stuck
if ThisPassword = "":
tkMessageBox.showerror("Error For User Here", parent=MyGui)
print "No password set!"
sys.exit(2)
else:
print "Password exists."
sys.exit(0)
我发现this article,其中WinAPI的赞扬LogonUser
被使用,但我不精明与C#。 Python更适合我的舒适区域,我无法弄清楚如何检查密码是否为空。我不想收集密码本身。