[英]Is there a way to Query current user's password age (in days) in C#?
Specifically, I want to determine the age of the current password so that I can display it in a textbox in a windows form. 具体来说,我想确定当前密码的使用期限,以便可以在Windows窗体的文本框中显示它。
Perhaps there is something in the WMIC library that I haven't seen? 也许WMIC库中有我没有看到的东西?
EDIT: 编辑:
If you were to use net user
+ windows username (which i can pull easily) you get results that include the date in which the password was SET and when it EXPIRES. 如果要使用
net user
+ Windows用户名(我可以轻松拉出),则会得到包含密码设置日期和密码到期时间的结果。 I want to pull that data. 我想提取这些数据。
Give this a try: 试试看:
using (var userEntry = new DirectoryEntry("WinNT://" + Environment.MachineName + '/' + Environment.UserName + ",user"))
{
int secondsSinceLastChange = (int)userEntry.InvokeGet("PasswordAge");
int daysSinceLastChange = secondsSinceLastChange / 60 / 60 / 24;
Console.WriteLine("{0} days since your last password change.", daysSinceLastChange);
}
You might need to add the System.DirectoryServices
reference. 您可能需要添加
System.DirectoryServices
引用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.