如何从窗口活动目录获取用户名密码

问题描述:

大家好,

我想知道如何根据Windows身份获取用户名和密码。如果用户根据活动目录有效,则没有登录屏幕,否则他可以访问网站。我们怎么设置这个?有人可以帮我从哪里开始?

Hi all ,
i want to know how to get user name and password based on windows identity. there will be no login screen if user is valid based on active directory he can access website otherwise not. how can we set this? can some one please help me where to start ?

内部加密的AD密码,除了密码剩余的所有用户信息,你可以使用PrincipalContext类获得可以在System.DirectoryServices中使用。



AD password encrypted internally so except password rest of all user info you can get by using "PrincipalContext " class that will be available in System.DirectoryServices.

// set up domain context
PrincipalContext ctx = new PrincipalContext(ContextType.Domain);

// find user by name
UserPrincipal user = UserPrincipal.FindByIdentity(ctx, "John Doe");

// if we found user - inspect its details
if(user != null)
{
    string firstName = user.GivenName;
    string lastName = user.Surname;
    string email = user.EmailAddress;
    string phone = user.VoiceTelephoneNumber;
}