Get current user's logon password
-
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'
-
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'
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
-
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
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'
-
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'
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
-
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'
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
-
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
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'
-
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'
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 -
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 KumarPlease 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 -
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 KumarHi 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 timeSteve 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'