Click here to Skip to main content
15,879,326 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
I have a windows application I want to use windows authentication log in at the beginning of my application please help!
Posted
Comments
[no name] 18-Jul-12 16:43pm    
Help with what? You have not stated a problem!
Have you tried anything. Please post your codes by clicking on Improve question link.
Trak4Net 18-Jul-12 17:57pm    
If you can give more detail to your design plan and what you would like to see happen that would be helpful. My first thought is why? If the user is logged into the computer they are already authenticated. Are you trying to limit allowed users by comparing to user list stored in your application somewhere? Are you trying to lock your application after a period of no activity and hence require re-authenticaiton to unlock? There are many design scenarios and different ways to "validate" windows login, it all depends on what your design requires, so definitely give more in depth detail to what you are looking for.

C#
class Program
    {

        [System.Runtime.InteropServices.DllImport("advapi32.dll")]
        public static extern bool LogonUser(string userName, string domainName, string password, int LogonType, int LogonProvider,ref IntPtr phToken);

        static void Main(string[] args)
        {
            Program obj = new Program();
            bool isValid = obj.IsValidateCredentials("myUserName","MyPassword","MyDomain");
            Console.WriteLine(isValid == true ? "Valid User details" : "Invalid User Details");
            Console.Read();
        }

        public bool IsValidateCredentials(string userName, string password, string domain)
        {
            IntPtr tokenHandler = IntPtr.Zero;
            bool isValid = LogonUser(userName, domain, password, 2, 0, ref tokenHandler);
            return isValid;
        }
    }
 
Share this answer
 
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900