Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Password Authentication

Status
Not open for further replies.

trivanka

Programmer
Apr 22, 2013
1
US
Hi,
I tried searching for vba code and was not able to find any.
I'm new to this thread and have a quick question.
I have created a userform with user name and password text box.
When user opens the excel sheet, the login userform will pop up asking for windows authetication.

Here is the code:

Declare Function GetUserName Lib "advapi32.dll" Alias _
"GetUserNameA" (ByVal lpBuffer As String, _
nSize 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

Private Sub UserForm_Initialize()
UserName.Text = GetWindowsLoginUserID
End Sub

Now, how can i authenticate the password once the OK button is clicked on the userform. What dll i need to use to verify password.

TIA
SFL
 
You could also do:
[tt]MsgBox Environ("USERNAME")[/tt]
(some people look down upon this way :-( )

I don't think you can have access to Windows password. And since user is logged in into Windows and you can detect who he/she is, then why the need for their password?

Have fun.

---- Andy
 
As Andrzejek asks, why do you need to do this. If you are retrieving the username the way you are then you are retrieving the name of a properly logged in and authenticated user, so why do you need authenticate them again?

Once we determine exactly what it is you need to achieve it willo be easier to advise (and note that it is possible to properly authenticate a Windows user/password, but we need to determine which method is appropriate - if any)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top