use Windows Username and Password to login my app...
Hi,
I don't want to store username and password into the database or file. I want that user will login through the logged in UserName Password and domain. for e.g.
If User ABC is logged into the system, then once he open the app, he will prompt for password, so that username will be the windows username and password has to be entered correctly.
Please let me know how I can achieve it....
.
Re: use Windows Username and Password to login my app...
All I'll give you is that you can use either the GetUserName or the GetUserNameEx API s to get the User name(s), to get the password, hmm I think that'll be too much of a risk posting such code on a public forum, at least IMHO.
Re: use Windows Username and Password to login my app...
Am still struggling.... :blush:
Re: use Windows Username and Password to login my app...
With what ¿ It cannot be with the Username ( not if you followed my advice ). As I also said ( to you ) in this thread and in numerous PMs, I don't think it's allowed to post such info about the Password here, and i don't want to ( and not going to ) break any rules..
Re: use Windows Username and Password to login my app...
Hey....
Hurrey I just got it now......
Thanks Hannes...
.
Re: use Windows Username and Password to login my app...
I use below code... It will not brings up the password but it will validate the user...
Code:
Public Declare Function NetUserChangePassword Lib "netapi32.dll" (ByVal sDomain As String, ByVal sUserName As String, ByVal sOldPassword As String, ByVal sNewPassword As String) As Long
Code:
Public Function UserValidate(sUserName As String, sPassword As String, Optional sDomain As String) As Boolean
Dim lReturn As Long
Const NERR_BASE = 2100
Const NERR_PasswordCantChange = NERR_BASE + 143
Const NERR_PasswordHistConflict = NERR_BASE + 144
Const NERR_PasswordTooShort = NERR_BASE + 145
Const NERR_PasswordTooRecent = NERR_BASE + 146
Const NERR_Cant_Change = 5 '"User can't change password" is checked
If Len(sDomain) = 0 Then
sDomain = Environ$("USERDOMAIN")
End If
'Call API to check password.
lReturn = NetUserChangePassword(StrConv(sDomain, vbUnicode), StrConv(sUserName, vbUnicode), StrConv(sPassword, vbUnicode), StrConv(sPassword, vbUnicode))
'Test return value.
Select Case lReturn
Case 0, NERR_PasswordCantChange, NERR_PasswordHistConflict, NERR_PasswordTooShort, NERR_PasswordTooRecent
UserValidate = True
Case 5
UserValidate = False
MsgBox "The user is not allowed to change passwords. Please remove the restriction.", vbCritical, "System Error"
Case Else
UserValidate = False
End Select
End Function
Private Sub Command1_Click()
If UserValidate(Text1.Text, Text2.Text, Text3.Text) = True Then
MsgBox "OK"
Else
MsgBox "Not OK"
End If
End Sub
Re: use Windows Username and Password to login my app...
You can't use StrConv(), as far as I can tell. Need a byte-array
Quote:
'Converts a Unicode-String to a Unicode-Byte-Array.
'Is used because VB always passes Strings as ANSI instead of Unicode.
Re: use Windows Username and Password to login my app...
But it is working fine....
Re: use Windows Username and Password to login my app...
Code:
Dim uname As String
uname = Environ$("Username")
MsgBox "Username = " & uname