decadence
Well-known Member
- Joined
- Oct 9, 2015
- Messages
- 525
- Office Version
- 365
- 2016
- 2013
- 2010
- 2007
- Platform
- Windows
Hi, I am trying to match the string typed into a user form against the windows password, how can I do this?
There are no passwords stored anywhere and the string that is typed is covered by stars so the passwords won't be visible when typed.
The code below is from Expert Exchange
There are no passwords stored anywhere and the string that is typed is covered by stars so the passwords won't be visible when typed.
The code below is from Expert Exchange
Code:
Option Explicit
Private Declare Function NetUserChangePassword Lib "Netapi32" (ByVal domainname As Long, ByVal UserName As Long, ByVal OldPassword As Long, ByVal NewPassword As Long) As Long
Private Const NERR_SUCCESS = 0
Private Const INVALID_PASSWORD = 86&
Private Const ACCESS_DENIED = 5
Private Sub Command1_Click()
Dim arg As String
arg = InputBox("Enter Password", "Window logon", vbNullString)
Select Case arg
Case vbNullString
If WindowPassword(arg, arg) Then
MsgBox "The current users password is blank."
End If
Case Else
If WindowPassword(arg, arg) Then
MsgBox "Windows Logon Password: " & arg
End If
End Select
End Sub
Function WindowPassword(ByVal oldpw As String, ByVal newpw As String, Optional ByVal UserName As String = vbNullString) As Boolean
Dim NetRet As Long
NetRet = NetUserChangePassword(0&, StrPtr(UserName), StrPtr(oldpw), StrPtr(newpw))
Select Case NetRet
Case NERR_SUCCESS
WindowPassword = True
Case INVALID_PASSWORD
MsgBox "Invalid Password"
Case ACCESS_DENIED
MsgBox "Access denied"
End Select
End Function