【问题标题】:Dotnet :- How to achieve windows authentication in window form application?Dotnet :- 如何在窗体应用程序中实现 Windows 身份验证?
【发布时间】:2011-03-16 06:10:15
【问题描述】:

我想做一个windows窗体应用,想用windows认证登录用户,必须在内网使用。应用程序应接受用户的用户名和密码并对其进行身份验证。如何做到这一点。

【问题讨论】:

  • 这是一个implementation
  • @Sanjeev :- 我用了你的想法。感谢您的帮助

标签: .net desktop-application


【解决方案1】:

您可以使用互操作服务实现此目的。使用下面的代码。

    [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;
    }

【讨论】:

    【解决方案2】:

    Environment.UserName 为您提供当前用户的用户名。由于用户已登录 Windows,因此不需要密码。

    替代:WindowsIdentity.GetCurrent()

    【讨论】:

    • Environment.Username 为我提供了登录的用户名,但是否足以允许登录我的应用程序?我自然需要将登录用户与我的用户表中的用户匹配,并且仅通过用户名来执行此操作看起来很弱。如果某人在他的计算机上创建了一个与 Intranet 域同名的本地域,并创建了一个与他想破解的用户同名的用户,该怎么办。所以他可以用任何他想要的用户登录。我错了吗?
    • 您找到解决方案了吗?我们的桌面应用程序有 Windows 身份验证,但我们不验证域,这意味着任何人都可以使用本地域和匹配的用户名登录。
    • 你可以使用WindowsIdentity.GetCurrent(),那里有域名
    【解决方案3】:

    请参考以下链接在 Intranet 中应用 windows 身份验证:

    http://msdn.microsoft.com/library/bb882216.aspx

    【讨论】:

      猜你喜欢
      • 2013-04-09
      • 1970-01-01
      • 1970-01-01
      • 2013-02-19
      • 2012-11-01
      • 2021-01-10
      • 2011-06-13
      • 2014-01-15
      • 1970-01-01
      相关资源
      最近更新 更多