# Re: ~SOS~请问有谁知道在输入一字串后，自动去侦测Windows Login的Password是否正确？

Posted by wawa on August 19, 1999 at 01:44:19:

In Reply to: ~SOS~请问有谁知道在输入一字串后，自动去侦测Windows Login的Password是否正确？ posted by 小宛 on August 18, 1999 at 23:35:45:

: 我目前在做一权限管制的程式，当User输入User与Password后，自动去侦测User在Windows Login
: 的User Name与Password，在Check User Name这部份已没问题，但是要去Check Login的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: