【发布时间】:2017-02-27 15:01:21
【问题描述】:
我正在尝试构建一个脚本来检查当前登录用户的本地帐户上的密码是否具有在 Windows 中不为空的密码。我需要将其作为安全合规性背景检查的一部分运行;它将向 Nagios 服务器报告。我需要在 Python 中完成这项工作,但如果 Python 不这样做,我对 PowerShell 持开放态度。
所以,脚本需要检测:
- 当前登录用户的用户名。
- 上述用户的密码是否为空。
- 如果密码不为空,则返回错误代码 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 更适合我的舒适区,我只是不知道如何检查密码集是否为空白。我不想自己收集密码。
【问题讨论】:
标签: python windows powershell