阅读背景:

C# Winform 使用域账号进行登录验证

来源:互联网 

     公司用的系统很多要求用域账号来登录,具体实现如下:


using System.DirectoryServices;


public string ValidateDomainUser(string Domain, string UserName, string Password)
        {
            DirectoryEntry entry = new DirectoryEntry(Domain, UserName, Password);
            try 
            {
                string objectSid = (new SecurityIdentifier((byte[])entry.Properties["objectSid"].Value, 0).Value);//如果账号不对则会抛出异常
                return objectSid;
            }
            catch
            {
                return null;
            }
            finally
            {
                entry.Dispose();
            }

        }
using Sys



你的当前访问异常,请进行认证后继续阅读剩余内容。

分享到: