Страница: 1 |
|
Вопрос: Как проверить правильность связки логин-пароль?
|
Добавлено: 29.12.08 23:34
|
|
Автор вопроса: Cooller
|
Здраствуйте!
Возникла проблемма...
На форме есть 2 listbox`а
В одном выбирается логин, в другом пароль...
Подскажите как проверить правильность связки логин-пароль?
Ответить
|
Номер ответа: 5 Автор ответа: Cooller
Вопросов: 11 Ответов: 32
|
Профиль | | #5
|
Добавлено: 30.12.08 08:37
|
1. получается тогда прога работать будет только под AD?
В первом случае - да. Есть идеи как сделать без AD?
Если использовать AD, почему функция CheckUser всегда возвращает true?
Private Function CheckUser(MyDomain As String, UserName As String, Password As String) As Boolean
Dim dso As IADsOpenDSObject
Dim obj
CheckUser = False
Set dso = GetObject("WinNT:"
On Error Resume Next
Set obj = dso.OpenDSObject("WinNT://" & MyDomain, UserName, Password, ADS_SECURE_AUTHENTICATION)
If Err.Number <> 0 Or obj Is Nothing Then
Err.Clear
Exit Function
End If
CheckUser = True
Set obj = Nothing
Set dso = Nothing
End Function
Private Sub 123_Click()
Dim a As Boolean
a = False
a =checkUser "Workgroup/my_Comp", "Cooller", "1"
If a = True Then MsgBox ("asdasd"
end sub
Ответить
|
Номер ответа: 7 Автор ответа: Arseny
ICQ: 298826769
Вопросов: 53 Ответов: 1732
|
Профиль | | #7
|
Добавлено: 30.12.08 08:51
|
нашел.
на форму - 2 текстбокса и батон.
- Option Explicit
-
- Private Declare Function LogonUser Lib "Advapi32" Alias "LogonUserA" (ByVal lpszUsername As String, ByVal lpszDomain As Any, ByVal lpszPassword As String, ByVal dwLogonType As Long, ByVal dwLogonProvider As Long, phToken As Long) As Long
- Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long
- Private Declare Function FormatMessage Lib "kernel32" Alias "FormatMessageA" (ByVal dwFlags As Long, lpSource As Any, ByVal dwMessageId As Long, ByVal dwLanguageId As Long, ByVal lpBuffer As String, ByVal nSize As Long, Arguments As Long) As Long
- Private Declare Function NetUserChangePassword Lib "netapi32.dll" (ByVal sDomain As String, ByVal sUserName As String, ByVal sOldPassword As String, ByVal sNewPassword As String) As Long
-
-
- Function UserValidate(sUserName As String, sPassword As String, Optional sDomain As String) As Boolean
- Dim lReturn As Long
- Const NERR_BASE = 2100
- Const NERR_PasswordCantChange = NERR_BASE + 143
- Const NERR_PasswordHistConflict = NERR_BASE + 144
- Const NERR_PasswordTooShort = NERR_BASE + 145
- Const NERR_PasswordTooRecent = NERR_BASE + 146
-
- If Len(sDomain) = 0 Then
- sDomain = Environ$("USERDOMAIN")
- End If
-
-
- lReturn = NetUserChangePassword(StrConv(sDomain, vbUnicode), StrConv(sUserName, vbUnicode), StrConv(sPassword, vbUnicode), StrConv(sPassword, vbUnicode))
-
-
- Select Case lReturn
- Case 0, NERR_PasswordCantChange, NERR_PasswordHistConflict, NERR_PasswordTooShort, NERR_PasswordTooRecent
- UserValidate = True
- Case Else
- UserValidate = False
- End Select
- End Function
-
-
-
- Function UserCheckPassword(ByVal Username As String, ByVal Password As String, Optional ByVal Domain As String = vbNullString) As Boolean
- Dim lRet As Long, hToken As Long
-
- Const LOGON32_LOGON_NETWORK = 3&
- Const LOGON32_LOGON_INTERACTIVE = 2&
- Const LOGON32_LOGON_BATCH = 4&
-
- Const LOGON32_PROVIDER_DEFAULT = 0&
- Const LOGON32_PROVIDER_WINNT40 = 2&
- Const LOGON32_PROVIDER_WINNT35 = 1&
- Const LOGON32_PROVIDER_WINNT50 = 3&
-
-
- lRet = LogonUser(Username, Domain, Password, LOGON32_LOGON_NETWORK, LOGON32_PROVIDER_DEFAULT, hToken)
-
- If lRet Then
-
- UserCheckPassword = True
- CloseHandle hToken
- Else
-
- Debug.Print "Error: " & DLLErrorText(Err.LastDllError)
- End If
- End Function
-
-
-
- Public Function DLLErrorText(ByVal lLastDLLError As Long) As String
- Dim sBuff As String * 256
- Dim lCount As Long
- Const FORMAT_MESSAGE_ALLOCATE_BUFFER = &H100, FORMAT_MESSAGE_ARGUMENT_ARRAY = &H2000
- Const FORMAT_MESSAGE_FROM_HMODULE = &H800, FORMAT_MESSAGE_FROM_STRING = &H400
- Const FORMAT_MESSAGE_FROM_SYSTEM = &H1000, FORMAT_MESSAGE_IGNORE_INSERTS = &H200
- Const FORMAT_MESSAGE_MAX_WIDTH_MASK = &HFF
-
- lCount = FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM Or FORMAT_MESSAGE_IGNORE_INSERTS, 0, lLastDLLError, 0&, sBuff, Len(sBuff), ByVal 0)
- If lCount Then
- DLLErrorText = Left$(sBuff, lCount - 2)
- End If
-
- End Function
-
- Private Sub Command1_Click()
-
- Debug.Print "Password valid, method 1: " & UserCheckPassword(Text1.Text, Text2.Text)
- Debug.Print "Password valid method 2: " & UserValidate(Text1.Text, Text2.Text)
- End Sub
Ответить
|
Страница: 1 |
Поиск по форуму