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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. Visual Basic
  4. Get current user's logon password

Get current user's logon password

Scheduled Pinned Locked Moved Visual Basic
question
9 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.
  • S Offline
    S Offline
    Steven J Jowett
    wrote on last edited by
    #1

    Is it possible to get the current user's windows logon password? I have an application which requires the user to logon, but would like to first try and logon with the same user name and password the user has as their windows logon, thus if they are the same, I will not need to ask the user for the logon name and password again.

    Steve Jowett ------------------------- Sometimes a man who deserves to be looked down upon because he is a fool, is only despised only because he is an 'I.T. Consultant'

    N S 2 Replies Last reply
    0
    • S Steven J Jowett

      Is it possible to get the current user's windows logon password? I have an application which requires the user to logon, but would like to first try and logon with the same user name and password the user has as their windows logon, thus if they are the same, I will not need to ask the user for the logon name and password again.

      Steve Jowett ------------------------- Sometimes a man who deserves to be looked down upon because he is a fool, is only despised only because he is an 'I.T. Consultant'

      N Offline
      N Offline
      Navneet Hegde
      wrote on last edited by
      #2

      Yes Of Course, You have to and if you have no proper right you can't proceed further . Thanks & wishes Navneet Hegde Nashik

      Develop2Program & Program2Develop

      S 1 Reply Last reply
      0
      • N Navneet Hegde

        Yes Of Course, You have to and if you have no proper right you can't proceed further . Thanks & wishes Navneet Hegde Nashik

        Develop2Program & Program2Develop

        S Offline
        S Offline
        Steven J Jowett
        wrote on last edited by
        #3

        My question was, although I did not actually say so, is "How do I get the current user's windows logon password, in VB.NEt code?" Sorry of not stating my requirement clearly. Regard

        Steve Jowett ------------------------- Sometimes a man who deserves to be looked down upon because he is a fool, is only despised only because he is an 'I.T. Consultant'

        N 1 Reply Last reply
        0
        • S Steven J Jowett

          Is it possible to get the current user's windows logon password? I have an application which requires the user to logon, but would like to first try and logon with the same user name and password the user has as their windows logon, thus if they are the same, I will not need to ask the user for the logon name and password again.

          Steve Jowett ------------------------- Sometimes a man who deserves to be looked down upon because he is a fool, is only despised only because he is an 'I.T. Consultant'

          S Offline
          S Offline
          SimulationofSai
          wrote on last edited by
          #4

          You can't get the password!!!! How did you ever expect the OS password to be accessible through API???:confused: Microsoft's done some stupid things regarding security, but this is not one of em. The password's hashed anyway. Yeah, you have software that can attempt to crack it. But in a normal PC, a reasonably strong password would take a few days or months to be rebuilt using dictionary cracking, if at all it succeeds. What you can do is get the current principal of the user and check if that login is within an Windows Role. Ex. if all your users are in the Role named "Administrators", you can get the thread.CurrentPrincipal and check if that Windows principal is in the role named "Administrators". If no, you can prompt for the user name and password again. Look up the WindowsPrincipal and WindowsIdentity classes for more info. SG

          S 1 Reply Last reply
          0
          • S Steven J Jowett

            My question was, although I did not actually say so, is "How do I get the current user's windows logon password, in VB.NEt code?" Sorry of not stating my requirement clearly. Regard

            Steve Jowett ------------------------- Sometimes a man who deserves to be looked down upon because he is a fool, is only despised only because he is an 'I.T. Consultant'

            N Offline
            N Offline
            Navneet Hegde
            wrote on last edited by
            #5

            ok, you mean you want your application to use windows login Authentication and proceed by using that username and password, Great Idea!, I will just try it out and will get back to you. If I am mistaken please pardon. Thanks & Regards Navneet Hegde Nashik

            Develop2Program & Program2Develop

            1 Reply Last reply
            0
            • S SimulationofSai

              You can't get the password!!!! How did you ever expect the OS password to be accessible through API???:confused: Microsoft's done some stupid things regarding security, but this is not one of em. The password's hashed anyway. Yeah, you have software that can attempt to crack it. But in a normal PC, a reasonably strong password would take a few days or months to be rebuilt using dictionary cracking, if at all it succeeds. What you can do is get the current principal of the user and check if that login is within an Windows Role. Ex. if all your users are in the Role named "Administrators", you can get the thread.CurrentPrincipal and check if that Windows principal is in the role named "Administrators". If no, you can prompt for the user name and password again. Look up the WindowsPrincipal and WindowsIdentity classes for more info. SG

              S Offline
              S Offline
              Steven J Jowett
              wrote on last edited by
              #6

              i_like_tintin wrote:

              How did you ever expect the OS password to be accessible through API???

              I didn't expect to be able to, but thought I would ask the question, just in case.

              Steve Jowett ------------------------- Sometimes a man who deserves to be looked down upon because he is a fool, is only despised only because he is an 'I.T. Consultant'

              K 1 Reply Last reply
              0
              • S Steven J Jowett

                i_like_tintin wrote:

                How did you ever expect the OS password to be accessible through API???

                I didn't expect to be able to, but thought I would ask the question, just in case.

                Steve Jowett ------------------------- Sometimes a man who deserves to be looked down upon because he is a fool, is only despised only because he is an 'I.T. Consultant'

                K Offline
                K Offline
                Kiran Kumar B
                wrote on last edited by
                #7

                Hi, I am now providing the code written for you in VB6. I will rewrite it in VB.NET and get back to you when I am free. I didn't find any API to retrieve password or hashed password. So, for username try this. I am providing you two ways. you can use anyone. 'Declare the API functions to access username. Private Declare Function GetUserName Lib "advapi32.dll" Alias "GetUserNameA" (ByVal lpBuffer As String, nSize As Long) As Long Private Declare Function GetEnvironmentVariable Lib "kernel32" Alias "GetEnvironmentVariableA" (ByVal lpName As String, ByVal lpBuffer As String, ByVal nSize As Long) As Long Dim kName As String * 255 ' For storing username with 255 char buffer. Dim kEnvVar As String * 255 Private Sub Command1_Click() Call GetUserName(kName, 255) ' First method of direct accessing username using API MsgBox kName Call GetEnvironmentVariable("USERNAME", kEnvVar, 255) '2nd method which uses windows environment variable to access the username MsgBox kEnvVar End Sub '----------- ' I hope this helps. ' Thanks, Kiran Kumar

                K 1 Reply Last reply
                0
                • K Kiran Kumar B

                  Hi, I am now providing the code written for you in VB6. I will rewrite it in VB.NET and get back to you when I am free. I didn't find any API to retrieve password or hashed password. So, for username try this. I am providing you two ways. you can use anyone. 'Declare the API functions to access username. Private Declare Function GetUserName Lib "advapi32.dll" Alias "GetUserNameA" (ByVal lpBuffer As String, nSize As Long) As Long Private Declare Function GetEnvironmentVariable Lib "kernel32" Alias "GetEnvironmentVariableA" (ByVal lpName As String, ByVal lpBuffer As String, ByVal nSize As Long) As Long Dim kName As String * 255 ' For storing username with 255 char buffer. Dim kEnvVar As String * 255 Private Sub Command1_Click() Call GetUserName(kName, 255) ' First method of direct accessing username using API MsgBox kName Call GetEnvironmentVariable("USERNAME", kEnvVar, 255) '2nd method which uses windows environment variable to access the username MsgBox kEnvVar End Sub '----------- ' I hope this helps. ' Thanks, Kiran Kumar

                  K Offline
                  K Offline
                  Kiran Kumar B
                  wrote on last edited by
                  #8

                  Please use this simple code to retrieve username in vb.net Public Class Form1 Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click MessageBox.Show(Environ("USERNAME")) End Sub End Class May I know for what purpose you are using the code to retrieve the windows password? so that I can guide you in another logic. Thanks, Kiran Kumar

                  S 1 Reply Last reply
                  0
                  • K Kiran Kumar B

                    Please use this simple code to retrieve username in vb.net Public Class Form1 Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click MessageBox.Show(Environ("USERNAME")) End Sub End Class May I know for what purpose you are using the code to retrieve the windows password? so that I can guide you in another logic. Thanks, Kiran Kumar

                    S Offline
                    S Offline
                    Steven J Jowett
                    wrote on last edited by
                    #9

                    Hi Kiran, I already know how to get the user name, but thanks for spending the time on it. It is appreciated. To get a user name the .NET way, use :- UserName = System.Environment.UserName The reason I was after the windows password, is so that I could then test the logon to the program I as writing, to see if the logon name and password are the same as the windows logon and if so logon to my program without asking the user for logon details again. It is not necessary, but would have been nice. Thanks for your time

                    Steve Jowett ------------------------- Sometimes a man who deserves to be looked down upon because he is a fool, is only despised only because he is an 'I.T. Consultant'

                    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