# Re: ~SOS~请问如何在输入一字串后，自动去Check Windows Login的Password是否正确呢？

Posted by wawa on August 19, 1999 at 01:45:23:

In Reply to: ~SOS~请问如何在输入一字串后，自动去Check Windows Login的Password是否正确呢？ posted by 小宛 on August 18, 1999 at 23:26:54:

: 我目前在做一权限管制程式，当User输入User Name和Password后，自动去侦测Windows Login的
: User Name 及 Password，在Check User Name上已无问题，但是要Check Password却大伤脑筋，
: 请问有谁知道如何达成呢？小女子在此先谢谢了！

'婓珨跺敦极奻氝楼谤跺恅挂遗 txtUser ﹜txtPass ㄛ珨跺偌听 cmdCheck ㄛ怀□眕狟测钨

Option Explicit

Private 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

Private Sub cmdCheck_Click()
Dim strUserName As String
Dim n As Long
Dim di As Long
Dim strPassTemp As String
Dim CheckUser, CheckPass As Boolean
di = GetUserName(strUserName, n)
strUserName = String(n - 1, 0)
di = GetUserName(strUserName, n)
CheckUser = (txtUser.Text = strUserName)
If Len(txtPass.Text) <= 0 Then
strPassTemp = ""
Else
strPassTemp = txtPass.Text
End If
CheckPass = (VerifyPass(strPassTemp))
If CheckUser And CheckPass Then
MsgBox "磁杨蚚誧ㄐ"
Else
MsgBox "准杨蚚誧ㄐ"
End If
End Sub

Function VerifyPass(strPass As String) As Boolean
Dim lResult As Long
If (WNetVerifyPassword(strPass, lResult)) <> 0 Then
MsgBox "System Error!"
Else
VerifyPass = IIf(lResult <> 0, True, False)
End If
End Function

Private Sub Form_Load()
txtUser.Text = ""
txtPass.Text = ""
End Sub

Follow Ups: