|
出处:http://support.microsoft.com/default.aspx?scid=http://support.microsoft.com:80/support/kb/articles/q279/8/15.asp&NoWebContent=1
Sample Code
The following Visual Basic module contains a public function called SSPValidateUser(). This function attempts to validate the supplied user name, domain name, and password by using SSPI functions.
'''' Module Name: SSPLogon.bas Option Explicit
Private Const HEAP_ZERO_MEMORY = &H8
Private Const SEC_WINNT_AUTH_IDENTITY_ANSI = &H1
Private Const SECBUFFER_TOKEN = &H2
Private Const SECURITY_NATIVE_DREP = &H10
Private Const SECPKG_CRED_INBOUND = &H1 Private Const SECPKG_CRED_OUTBOUND = &H2
Private Const SEC_I_CONTINUE_NEEDED = &H90312 Private Const SEC_I_COMPLETE_NEEDED = &H90313 Private Const SEC_I_COMPLETE_AND_CONTINUE = &H90314
Private Const VER_PLATFORM_WIN32_NT = &H2
Type SecPkgInfo fCapabilities As Long wVersion As Integer wRPCID As Integer cbMaxToken As Long Name As Long Comment As Long End Type
Type SecHandle dwLower As Long dwUpper As Long End Type
Type AUTH_SEQ fInitialized As Boolean fHaveCredHandle As Boolean fHaveCtxtHandle As Boolean hcred As SecHandle hctxt As SecHandle End Type
Type SEC_WINNT_AUTH_IDENTITY User As String UserLength As Long Domain As String DomainLength As Long Password As String PasswordLength As Long Flags As Long End Type
Type TimeStamp LowPart As Long HighPart As Long End Type
Type SecBuffer cbBuffer As Long BufferType As Long pvBuffer As Long End Type
Type SecBufferDesc ulVersion As Long cBuffers As Long pBuffers As Long End Type
Public Type OSVERSIONINFO dwOSVersionInfoSize As Long dwMajorVersion As Long dwMinorVersion As Long dwBuildNumber As Long dwPlatformId As Long szCSDVersion As String * 128 End Type
Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" _ (Destination As Any, Source As Any, ByVal Length As Long)
Private Declare Function NT4QuerySecurityPackageInfo Lib "security" _ Alias "QuerySecurityPackageInfoA" (ByVal PackageName As String, _ ByRef pPackageInfo As Long) As Long
Private Declare Function QuerySecurityPackageInfo Lib "secur32" _ Alias "QuerySecurityPackageInfoA" (ByVal PackageName As String, _ ByRef pPackageInfo As Long) As Long
Private Declare Function NT4FreeContextBuffer Lib "security" _ Alias "FreeContextBuffer" (ByVal pvContextBuffer As Long) As Long
Private Declare Function FreeContextBuffer Lib "secur32" _ (ByVal pvContextBuffer As Long) As Long
Private Declare Function NT4InitializeSecurityContext Lib "security" _ Alias "InitializeSecurityContextA" _ (ByRef phCredential As SecHandle, ByRef phContext As SecHandle, _ ByVal pszTargetName As Long, ByVal fContextReq As Long, _ ByVal Reserved1 As Long, ByVal TargetDataRep As Long, _ ByRef pInput As SecBufferDesc, ByVal Reserved2 As Long, _ ByRef phNewContext As SecHandle, ByRef pOutput As SecBufferDesc, _ ByRef pfContextAttr As Long, ByRef ptsExpiry As TimeStamp) As Long
Private Declare Function InitializeSecurityContext Lib "secur32" _ Alias "InitializeSecurityContextA" _ (ByRef phCredential As SecHandle, ByRef phContext As SecHandle, _ ByVal pszTargetName As Long, ByVal fContextReq As Long, _ ByVal Reserved1 As Long, ByVal TargetDataRep As Long, _ ByRef pInput As SecBufferDesc, ByVal Reserved2 As Long, _ ByRef phNewContext As SecHandle, ByRef pOutput As SecBufferDesc, _ ByRef pfContextAttr As Long, ByRef ptsExpiry As TimeStamp) As Long
Private Declare Function NT4InitializeSecurityContext2 Lib "security" _ Alias "InitializeSecurityContextA" _ (ByRef phCredential As SecHandle, ByVal phContext As Long, _ ByVal pszTargetName As Long, ByVal fContextReq As Long, _ ByVal Reserved1 As Long, ByVal TargetDataRep As Long, _ ByVal pInput As Long, ByVal Reserved2 As Long, _ ByRef phNewContext As SecHandle, ByRef pOutput As SecBufferDesc, _ ByRef pfContextAttr As Long, ByRef ptsExpiry As TimeStamp) As Long
Private Declare Function InitializeSecurityContext2 Lib "secur32" _ Alias "InitializeSecurityContextA" _ (ByRef phCredential As SecHandle, ByVal phContext As Long, _ ByVal pszTargetName As Long, ByVal fContextReq As Long, _ ByVal Reserved1 As Long, ByVal TargetDataRep As Long, _ ByVal pInput As Long, ByVal Reserved2 As Long, _ ByRef phNewContext As SecHandle, ByRef pOutput As SecBufferDesc, _ ByRef pfContextAttr As Long, ByRef ptsExpiry As TimeStamp) As Long
Private Declare Function NT4AcquireCredentialsHandle Lib "security" _ Alias "AcquireCredentialsHandleA" (ByVal pszPrincipal As Long, _ ByVal pszPackage As String, ByVal fCredentialUse As Long, _ ByVal pvLogonId As Long, _ ByRef pAuthData As SEC_WINNT_AUTH_IDENTITY, _ ByVal pGetKeyFn As Long, ByVal pvGetKeyArgument As Long, _ ByRef phCredential As SecHandle, ByRef ptsExpiry As TimeStamp) _ As Long
Private Declare Function AcquireCredentialsHandle Lib "secur32" _ Alias "AcquireCredentialsHandleA" (ByVal pszPrincipal As Long, _ ByVal pszPackage As String, ByVal fCredentialUse As Long, _ ByVal pvLogonId As Long, _ ByRef pAuthData As SEC_WINNT_AUTH_IDENTITY, _ ByVal pGetKeyFn As Long, ByVal pvGetKeyArgument As Long, _ ByRef phCredential As SecHandle, ByRef ptsExpiry As TimeStamp) _ As Long
Private Declare Function NT4AcquireCredentialsHandle2 Lib "security" _ Alias "AcquireCredentialsHandleA" (ByVal pszPrincipal As Long, _ ByVal pszPackage As String, ByVal fCredentialUse As Long, _ ByVal pvLogonId As Long, ByVal pAuthData As Long, _ ByVal pGetKeyFn As Long, ByVal pvGetKeyArgument As Long, _ ByRef phCredential As SecHandle, ByRef ptsExpiry As TimeStamp) _ As Long
Private Declare Function AcquireCredentialsHandle2 Lib "secur32" _ Alias "AcquireCredentialsHandleA" (ByVal pszPrincipal As Long, _ ByVal pszPackage As String, ByVal fCredentialUse As Long, _ ByVal pvLogonId As Long, ByVal pAuthData As Long, _ ByVal pGetKeyFn As Long, ByVal pvGetKeyArgument As Long, _ ByRef phCredential As SecHandle, ByRef ptsExpiry As TimeStamp) _ As Long
Private Declare Function NT4AcceptSecurityContext Lib "security" _ Alias "AcceptSecurityContext" (ByRef phCredential As SecHandle, _ ByRef phContext As SecHandle, ByRef pInput As SecBufferDesc, _ ByVal fContextReq As Long, ByVal TargetDataRep As Long, _ ByRef phNewContext As SecHandle, ByRef pOutput As SecBufferDesc, _ ByRef pfContextAttr As Long, ByRef ptsExpiry As TimeStamp) As Long
Private Declare Function AcceptSecurityContext Lib "secur32" _ (ByRef phCredential As SecHandle, _ ByRef phContext As SecHandle, ByRef pInput As SecBufferDesc, _ ByVal fContextReq As Long, ByVal TargetDataRep As Long, _ ByRef phNewContext As SecHandle, ByRef pOutput As SecBufferDesc, _ ByRef pfContextAttr As Long, ByRef ptsExpiry As TimeStamp) As Long
Private Declare Function NT4AcceptSecurityContext2 Lib "security" _ &nb [1] [2] [3] [4] 下一页 没有相关教程
|