Dotnet :- How to achieve windows authentication in window form application?

后端 未结 3 1268
心在旅途
心在旅途 2021-01-23 11:35

I want to make a windows form application and want to use windows authentication to log in the user, it has to be used in intranet. the applcation should accept the user name an

相关标签:
3条回答
  • 2021-01-23 11:58

    Please refer the following link to apply windows Authentication in Intranet:

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

    0 讨论(0)
  • 2021-01-23 12:07

    You can achieve this using Interop Services. Use the below Code.

        [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;
        }
    
    0 讨论(0)
  • 2021-01-23 12:09

    Environment.UserName gives you the username of the current user. A password is not needed since the user have logged into windows.

    Alternative: WindowsIdentity.GetCurrent()

    0 讨论(0)
提交回复
热议问题