Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. How to get the windows login un and pw in c#

How to get the windows login un and pw in c#

Scheduled Pinned Locked Moved C#
csharptutorial
5 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • V Offline
    V Offline
    VijayaRam
    wrote on last edited by
    #1

    Can any one tell how to get the username and password from the windows login, for processing inside a c# windows application. Thanks in advance, regards,

    VijayaRam

    C M 2 Replies Last reply
    0
    • V VijayaRam

      Can any one tell how to get the username and password from the windows login, for processing inside a c# windows application. Thanks in advance, regards,

      VijayaRam

      C Offline
      C Offline
      Colin Angus Mackay
      wrote on last edited by
      #2

      You cannot get the windows password.


      Upcoming events: * Glasgow Geek Dinner (5th March) * Glasgow: Tell us what you want to see in 2007 My: Website | Blog | Photos

      V 1 Reply Last reply
      0
      • C Colin Angus Mackay

        You cannot get the windows password.


        Upcoming events: * Glasgow Geek Dinner (5th March) * Glasgow: Tell us what you want to see in 2007 My: Website | Blog | Photos

        V Offline
        V Offline
        VijayaRam
        wrote on last edited by
        #3

        Or tell me how to get windows username Thanks and regards,

        VijayaRam

        X 1 Reply Last reply
        0
        • V VijayaRam

          Or tell me how to get windows username Thanks and regards,

          VijayaRam

          X Offline
          X Offline
          xstoneheartx
          wrote on last edited by
          #4

          you can use System.Environment.UserName

          1 Reply Last reply
          0
          • V VijayaRam

            Can any one tell how to get the username and password from the windows login, for processing inside a c# windows application. Thanks in advance, regards,

            VijayaRam

            M Offline
            M Offline
            MrEyes
            wrote on last edited by
            #5

            It isnt possible to get the user password, however you can validate it using the follow api call

            const int LOGON32_LOGON_INTERACTIVE = 2;
            const int LOGON32_PROVIDER_DEFAULT = 0;

            [DllImport("advapi32.dll", SetLastError=true)]
            private static extern bool LogonUser(String lpszUsername, String lpszDomain, String lpszPassword, int dwLogonType, int dwLogonProvider, ref IntPtr phToken);

            private void DoLogonCheck(string userName, string domainName, string password)
            {
            IntPtr phToken = IntPtr.Zero;
            bool logonRes = LogonUser(
            userName,
            domainName,
            password,
            LOGON32_LOGON_INTERACTIVE,
            LOGON32_PROVIDER_DEFAULT,
            ref phToken);

            if (logonRes)
            {
            Console.WriteLine("Good logon with username : {0}", userName)
            }
            else
            {
            Console.WriteLine("Bad logon with username : {0}", userName)
            }
            }

            I use a similar piece of code to validate that the user true user is sat in front of the machine and not that they have left it unlocked.

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups