I am trying to put a login dialog on my application.
In order to Authenticate the username and password I want to use the windows login.
Does anybody know if this is possible and If so how do I do it.
Regards
Printable View
I am trying to put a login dialog on my application.
In order to Authenticate the username and password I want to use the windows login.
Does anybody know if this is possible and If so how do I do it.
Regards
have a look@this sample code:
Put this in a module:
Option Explicit
Declare Function GetUserName Lib "advapi32.dll" Alias _
"GetUserNameA" (ByVal lpBuffer As String, _
nSize As Long) As Long
Private Declare Function WNetVerifyPassword Lib "mpr.dll" Alias _
"WNetVerifyPasswordA" (ByVal lpszPassword As String, _
ByRef pfMatch As Long) As Long
Public Function GetWindowsLoginUserID() As String
Dim rtn As Long
Dim sBuffer As String
Dim lSize As Long
sBuffer = String$(260, Chr$(0))
lSize = Len(sBuffer)
rtn = GetUserName(sBuffer, lSize)
If rtn Then
sBuffer = Left$(sBuffer, lSize)
'Reformat string
If InStr(sBuffer, Chr$(0)) Then
sBuffer = Left$(sBuffer, InStr(sBuffer, Chr$(0)) - 1)
End If
GetWindowsLoginUserID = sBuffer
Else
'Error!
GetWindowsLoginUserID = ""
End If
End Function
Public Function VerifyWindowsLoginUserPassword _
(ByVal Password As String) As Boolean
Dim rtn As Long, Match As Long
rtn = WNetVerifyPassword(Password, Match)
If rtn Then
VerifyWindowsLoginUserPassword = False
Else
VerifyWindowsLoginUserPassword = (Match <> 0)
End If
End Function
and this in the form:
Private Sub Command1_Click()
If VerifyWindowsLoginUserPassword(Text2.Text) Then
MsgBox "Pwd OK"
Else
MsgBox "Wrong Pwd"
End If
End Sub
Private Sub Form_Load()
Text1.Text = GetWindowsLoginUserID
End Sub
nialler.....The user of ur app uses ur application only after logging in to Windows then whats the meaning in asking for the windows login in ur app?
Mabey nailer was thinking of a multiuser computer with one logon. in that case the only person that can use the app he designs is the one who setup the password, Or if you leave the computer unattended while logged on.
It is a minor security percaution and i am sure that nailer has his reasons.
Quote:
There are no stupid questions, just stupid people to interperate them.
Thanks everybody for the help.
The reason I need to know is that the application, at certain points, will require certain administrative rights, so digital signaturing is required, which is no good if somebody can just walk over to the computer and do it for you.
Thanks, Nice, for the help, much appreciated!
Regards
my post was directed towards faisalkm.