473,508 Members | 3,343 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Vb Issues

1 New Member
I have been asked to ad some code to one of our databases.. currently this database looks to active directory for log in information... we would like it to look to a specific OU, is that possible ... i have copied the code into here. this has my additions that dont work in it

Expand|Select|Wrap|Line Numbers
  1. Option Explicit
  2.  
  3. 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
  4. Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long
  5. 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
  6. 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
  7.  
  8. 'Purpose   :    Checks if a the NT password for a user is correct.
  9. 'Inputs    :    UserName                The username
  10. '               Password                The password
  11. '               [Domain]                If DOMAIN is omitted uses the local account database.
  12. 'Outputs   :    Returns True if the password and user name are valid.
  13. 'Notes     :    Windows NT and 2000 ONLY. Will work on any machine.
  14. '               Slower than the UserCheckPassword function, but more reliable.
  15.  
  16. If LogonUser = ITAdmins Is True Then
  17.  
  18.  
  19.  
  20.  
  21.  
  22.  
  23.  
  24.  
  25.  
  26. Function UserValidate(sUserName As String, sPassword As String, Optional sDomain As String) As Boolean
  27.     Dim lReturn As Long
  28.     Const NERR_BASE = 2100
  29.     Const NERR_PasswordCantChange = NERR_BASE + 143
  30.     Const NERR_PasswordHistConflict = NERR_BASE + 144
  31.     Const NERR_PasswordTooShort = NERR_BASE + 145
  32.     Const NERR_PasswordTooRecent = NERR_BASE + 146
  33.  
  34.     If Len(sDomain) = 0 Then
  35.         sDomain = Environ$("USERDOMAIN")
  36.     End If
  37.  
  38.     'Call API to check password.
  39.     lReturn = NetUserChangePassword(StrConv(sDomain, vbUnicode), StrConv(sUserName, vbUnicode), StrConv(sPassword, vbUnicode), StrConv(sPassword, vbUnicode))
  40.  
  41.     'Test return value.
  42.     Select Case lReturn
  43.     Case 0, NERR_PasswordCantChange, NERR_PasswordHistConflict, NERR_PasswordTooShort, NERR_PasswordTooRecent
  44.         UserValidate = True
  45.     Case Else
  46.         UserValidate = False
  47.     End Select
  48. End Function
  49.  
  50.  
  51. 'Purpose   :    Checks if a the NT password for a user is correct.
  52. 'Inputs    :    UserName                The username
  53. '               Password                The password
  54. '               [Domain]                If DOMAIN is omitted uses the local account database.
  55. 'Outputs   :    Returns True if the password and user name are valid.
  56. 'Notes     :    Windows NT and 2000 ONLY. Requires correct permissions to run (must have
  57. '               the SE_TCB_NAME privilege. In User Manager, this is the "Act as part of the
  58. '               Operating System" right).
  59.  
  60. Function UserCheckPassword(ByVal UserName As String, ByVal Password As String, Optional ByVal Domain As String = vbNullString) As Boolean
  61.     Dim lRet As Long, hToken As Long
  62.  
  63.     Const LOGON32_LOGON_NETWORK = 3&            'Intended for high performance servers to authenticate clear text passwords
  64.     Const LOGON32_LOGON_INTERACTIVE = 2&        'Intended for users who will be interactively using the machine, such as a user being logged on by a terminal server
  65.     Const LOGON32_LOGON_BATCH = 4&
  66.  
  67.     Const LOGON32_PROVIDER_DEFAULT = 0&         'Use the standard logon provider for the system
  68.     Const LOGON32_PROVIDER_WINNT40 = 2&         'Use the Windows NT 4.0 logon provider
  69.     Const LOGON32_PROVIDER_WINNT35 = 1&         'Use the Windows NT 3.5 logon provider
  70.     Const LOGON32_PROVIDER_WINNT50 = 3&         'Use the Windows 2000 logon provider.
  71.  
  72.     'Check the username and password
  73.     lRet = LogonUser(UserName, Domain, Password, LOGON32_LOGON_NETWORK, LOGON32_PROVIDER_DEFAULT, hToken)
  74.  
  75.     If lRet Then
  76.         'Password correct
  77.         UserCheckPassword = True
  78.         CloseHandle hToken
  79.     Else
  80.         'Failed:
  81.         Debug.Print "Error: " & DLLErrorText(Err.LastDllError)
  82.     End If
  83. End Function
  84.  
  85.  
  86. 'Purpose     :  Return the error message associated with LastDLLError
  87. 'Inputs      :  lLastDLLError               The error number of the last DLL error (from Err.LastDllError)
  88. 'Outputs     :  Returns the error message associated with the DLL error number
  89. 'Notes       :
  90. 'Revisions   :
  91.  
  92. Public Function DLLErrorText(ByVal lLastDLLError As Long) As String
  93.     Dim sBuff As String * 256
  94.     Dim lCount As Long
  95.     Const FORMAT_MESSAGE_ALLOCATE_BUFFER = &H100, FORMAT_MESSAGE_ARGUMENT_ARRAY = &H2000
  96.     Const FORMAT_MESSAGE_FROM_HMODULE = &H800, FORMAT_MESSAGE_FROM_STRING = &H400
  97.     Const FORMAT_MESSAGE_FROM_SYSTEM = &H1000, FORMAT_MESSAGE_IGNORE_INSERTS = &H200
  98.     Const FORMAT_MESSAGE_MAX_WIDTH_MASK = &HFF
  99.  
  100.     lCount = FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM Or FORMAT_MESSAGE_IGNORE_INSERTS, 0, lLastDLLError, 0&, sBuff, Len(sBuff), ByVal 0)
  101.     If lCount Then
  102.         DLLErrorText = Left$(sBuff, lCount - 2)    'Remove line feeds
  103.     End If
  104.  
  105. End Function
  106.  
  107. Sub TestLogin()
  108.     'Check if password is valid
  109.     Debug.Print "Password valid, method 1: " & UserCheckPassword("rcurran", InputBox("Password"))
  110.     Debug.Print "Password valid method 2: " & UserValidate("rcurran", InputBox("Password"))
  111.     'Debug.Print "Password valid, method 1: " & UserCheckPassword(Environ$("USERNAME"), "password")
  112.     'Debug.Print "Password valid method 2: " & UserValidate(Environ$("USERNAME"), "password")
  113. End Sub
  114.  
  115. Function bConfirmCreateLogin(psUser As String, psPassword As String, Optional psDomain As String) As Boolean
  116.     On Error GoTo R_Err
  117.     Dim sSQL As String
  118.     bConfirmCreateLogin = False
  119.     If UserValidate(psUser, psPassword, psDomain) = True Then
  120.         'Confirm User Created
  121.         If DCount("UserID", "tblUser", "UserName=""" & Nz(psUser, "") & """ ") = 0 Then
  122.             sSQL = "INSERT INTO tblUser (UserName, FullName) SELECT """ & Nz(psUser, "") & """,""" & UCase(Nz(psUser, "")) & """ "
  123.             DoCmd.SetWarnings False
  124.             DoCmd.RunSQL (sSQL)
  125.         End If
  126.         bConfirmCreateLogin = True
  127.     End If
  128. R_Err:
  129.     On Error Resume Next
  130.     DoCmd.SetWarnings True
  131.     Exit Function
  132. R_Exit:
  133.     bConfirmCreateLogin = False
  134.     Resume R_Err
  135. End Function
  136. Else: MsgBox "YOU ARE NOT AUTHORIZED"
  137. End If
Aug 13 '07 #1
0 1064

Sign in to post your reply or Sign up for a free account.

Similar topics

2
2072
by: Tom Loredo | last post by:
Hi folks- I'm about to move from a Solaris 8/SPARC environment to a Dell running RedHat 9. Are there any issues I need to be aware of in bringing my Python code over (mostly scientific...
28
2765
by: grahamd | last post by:
Who are the appropriate people to report security problems to in respect of a module included with the Python distribution? I don't feel it appropriate to be reporting it on general mailing lists.
5
4672
by: sandy | last post by:
Hi All, I am a newbie to MySQL and Python. At the first place, I would like to know what are the general performance issues (if any) of using MySQL with Python. By performance, I wanted to...
2
2267
by: malcolm | last post by:
Hello, We have a robust (.NET 1.1 c# winforms) client-server application that utilizes many typed DataSets, typed DataTables and typed DataRows. Our application is a series of windows and popup...
1
1657
by: Aliandro | last post by:
Hi Does any one know where I can find information regarding any issues with SQL and IIS being run under windows XP SP2? as I am in the process of programmning in Dot net and neet some way of...
7
1836
by: David Laub | last post by:
I have stumbled across various Netscape issues, none of which appear to be solvable by tweaking the clientTarget or targetSchema properties. At this point, I'm not even interested in "solving"...
2
3035
by: G2 | last post by:
Hi We are dealing with significant browser compatibility issues with Netscape 5.x+ browsers and Mac IE. I am sure most web developers have faced similar issues in the past. Can anyone give me their...
1
1944
by: GaryDean | last post by:
We have been developing all of our .net applications on 32 bit windows using 32 bit SQL Server. We are being asked to now deploy to servers running 64bit windows and 64bit SQL Server. Are there...
3
1636
by: eschneider | last post by:
Just some common issues with WS: Using custom objects: When objects change, seems you are always fixing some issue. Update references, which sometimes does not work. Deployment: Weird errors...
0
7129
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7333
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7398
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
7061
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7502
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5637
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
3208
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3194
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
428
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.