我设法做了一些事情,但我遇到的问题是到期天数是负数(daysleft参数),但我仍然可以登录.
string domainAndUsername = @"LDAP://ldapUrl";DirectoryEntry root = new DirectoryEntry(ldapServer,userID,userPwd,AuthenticationTypes.Secure);DirectorySearcher mySearcher = new DirectorySearcher(root);SearchResultCollection results;string filter = "maxPwdAge=*";mySearcher.Filter = filter;results = mySearcher.FindAll();long maxDays = 0;if (results.Count >= 1){ Int64 maxPwdAge = (Int64)results[0].PropertIEs["maxPwdAge"][0]; maxDays = maxPwdAge / -864000000000;}mySearcher = new DirectorySearcher(root);mySearcher.Filter = "(&(objectcategory=user)(samaccountname=" + userID + "))";results = mySearcher.FindAll();long daysleft = 0;if (results.Count >= 1){ var lastChanged = results[0].PropertIEs["pwdLastSet"][0]; daysleft = maxDays - DateTime.Today.Subtract( DateTime.FromfileTime((long)lastChanged)).Days;}
由于用户无法登录,如果帐户已过期,我猜我的错误是计算帐户到期之前的剩余天数…但我似乎无法找到它的位置.
解决方法@H_419_18@ 这个片段工作正常,我还有三天要改变我的pw,包括今天:public static voID Main(string[] args) { const ulong dataFromAD = 0xFFFFE86D079B8000; var ticks = -unchecked((long)dataFromAD); var maxPwdAge = TimeSpan.FromTicks(ticks); var pwdLastSet = new DateTime(2015,12,16,9,19,13); var pwdDeadline = (pwdLastSet + maxPwdAge).Date; Console.Writeline(pwdDeadline); Console.Writeline(pwdDeadline - DateTime.Today); Console.ReadKey(true); }
我还验证了TimeSpan.FromTicks( – (long)results [0] .PropertIEs [“maxPwdAge”] [0])和DateTime.FromfileTime((long)results [0] .PropertIEs [“pwdLastSet”] [0])表达式正确地从我们的AD中提取值.
总结以上是内存溢出为你收集整理的c# – LDAP密码到期日全部内容,希望文章能够帮你解决c# – LDAP密码到期日所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)