【发布时间】:2011-03-16 06:10:15
【问题描述】:
我想做一个windows窗体应用,想用windows认证登录用户,必须在内网使用。应用程序应接受用户的用户名和密码并对其进行身份验证。如何做到这一点。
【问题讨论】:
-
这是一个implementation
-
@Sanjeev :- 我用了你的想法。感谢您的帮助
我想做一个windows窗体应用,想用windows认证登录用户,必须在内网使用。应用程序应接受用户的用户名和密码并对其进行身份验证。如何做到这一点。
【问题讨论】:
您可以使用互操作服务实现此目的。使用下面的代码。
[System.Runtime.InteropServices.DllImport("advapi32.dll")]
public static extern bool LogonUser(string userName, string domainName, string password, int LogonType, int LogonProvider, ref IntPtr phToken);
public bool IsValidateCredentials(string userName, string password, string domain)
{
IntPtr tokenHandler = IntPtr.Zero;
bool isValid = LogonUser(userName, domain, password, 3, 0, ref tokenHandler);
return isValid;
}
【讨论】:
Environment.UserName 为您提供当前用户的用户名。由于用户已登录 Windows,因此不需要密码。
【讨论】:
WindowsIdentity.GetCurrent(),那里有域名
请参考以下链接在 Intranet 中应用 windows 身份验证:
【讨论】: