473,883 Members | 1,666 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Log in form problems

9 New Member
Hi,

I am working on a log in form for an Access 2003 db. Because the built-in jet database engine doesn't supply the ability to record every log attempt, failed attempt, validate passwords, user lock after X failed log attempts, ... I desided to program one of my own.

The code itselves works fine but I cannot write the value of intLogonAttempt to tbl_users, I would like to lock the user after 3 failed log attempts, and made a field called [Attempts] into tbl_users, which count every faild log attempts and a field called [lock_user] as boolean to activate the user lock.

I can count with intlogAttempts but I cannot write the value to the tbl to use to count every failed log on attempt, it always goes back to zero and even with a macro It doesn't work.

My goal is to,create a complete log on record where the db will write every log on (failed or succesfull) to a record, as well as every change of password, new users, deactivated users,....

Help is greatly appriciated.

thanks,
Tom
Expand|Select|Wrap|Line Numbers
  1. ' Module   : mod_display_menu
  2. ' Function : display the switchboard after checking the access and password and password expiry date
  3.  
  4. Option Compare Database
  5. Option Explicit
  6.  
  7. Sub display_menu()
  8. On Error GoTo err_display_menu
  9.  
  10.  
  11.  
  12. '*************************************************************
  13. '*          Check userId and access level                    *
  14. '*************************************************************
  15. Dim access_level As Integer
  16. Dim finish_Date As Date
  17. Dim port_syd As String
  18. Dim valid_user As Integer
  19. Dim check_user As Integer
  20. Dim password_period As Date
  21. Dim check_password As String
  22. Dim strmsg As String
  23. Dim bln_lock As Boolean
  24. Static intLogonAttempts As Integer
  25.  
  26. valid_user = 2
  27.  
  28.  
  29.  
  30.  
  31. ' ***********************************************
  32. ' *             Validate user_id                *
  33. ' ***********************************************
  34. check_user = DCount("[user_id]", "tbl_users", "user_id=forms!frm_main!user_id")
  35. bln_lock = DLookup("[Control_lock]", "tbl_users", "user_id=forms!frm_main!user_id")
  36.     If check_user = 1 And bln_lock = False Then
  37.         valid_user = 2
  38.     Else
  39.         valid_user = 0
  40.    End If
  41.  
  42.  
  43.  
  44.  
  45. ' ********************************************************************************
  46. ' *         Validate password                                                    *
  47. ' *         REMARK: Changed UCase scenario to allow upper and lower case symbols *
  48. ' ********************************************************************************
  49. If valid_user = 2 Then
  50.    check_password = DLookup("[passwords]", "tbl_users", "user_id=forms!frm_main!user_id")
  51.    If check_password = Forms!frm_main!password Then
  52.         valid_user = 2
  53.    Else
  54.         valid_user = 1
  55.    End If
  56.  
  57. End If
  58.  
  59.  
  60.  
  61. ' **********************************************
  62. ' *         Validate access_level              *
  63. ' **********************************************
  64. If valid_user = 2 Then
  65.     access_level = DLookup("[access_level]", "tbl_users", "user_id=forms!frm_main!user_id")
  66. End If
  67.  
  68. Select Case valid_user
  69.  
  70.     Case 0, 1
  71.             strmsg = " Access Denied" & _
  72.                         vbCrLf & " Contact your Administrator if the problem persists.   "
  73.             MsgBox strmsg, vbCritical, "INVALID USER ID or PASSWORD"
  74.  
  75.             intLogonAttempts = DLookup("[Attempts]", "tbl_users", "user_id=forms!frm_main!user_id")
  76.  
  77.             intLogonAttempts = intLogonAttempts + 1
  78.  
  79.  
  80.             'write intlogonAttempt to [Attempts] in tbl_users
  81.  
  82.  
  83.             If intLogonAttempts > 3 Then
  84.                 MsgBox "You are locked out this database.  Please contact your System Administrator.", vbCritical, "Restricted Access!"
  85.                 bln_lock = True
  86.                 'Application.Quit
  87.             End If
  88.  
  89.  
  90.            ' DoCmd.Quit
  91.  
  92.     Case 2
  93.             Select Case access_level
  94.                Case 1   ' Level1 menu; System Administrator
  95.                         ' validate password expiry
  96.                       password_period = DLookup("[password_date]", "tbl_users", "user_id = forms!frm_main!user_id")
  97.                       If password_period < date - 30 Then
  98.                             strmsg = " Your password has expired. You must change your password"
  99.                             MsgBox strmsg, vbInformation, "Expired Password"
  100.                             DoCmd.OpenForm "frm_change_password", acNormal
  101.                         Else
  102.                             DoCmd.OpenForm "switchboard"
  103.                         End If
  104.  
  105.                Case 2   ' Level2 menu; super visor acount
  106.                         ' validate password expiry
  107.                       password_period = DLookup("[password_date]", "tbl_users", "user_id = forms!frm_main!user_id")
  108.                       If password_period < date - 90 Then
  109.                             strmsg = " Your password has expired. You must change your password"
  110.                             MsgBox strmsg, vbInformation, "Expired Password"
  111.                             DoCmd.OpenForm "frm_change_password", acNormal
  112.                         Else
  113.                             DoCmd.OpenForm "switchboard"
  114.                         End If
  115.  
  116.                Case 3   ' Level3 menu; user acount
  117.                         ' validate password expiry
  118.                       password_period = DLookup("[password_date]", "tbl_users", "user_id = forms!frm_main!user_id")
  119.                       If password_period < date - 90 Then
  120.                             strmsg = " Your password has expired. You must change your password"
  121.                             MsgBox strmsg, vbInformation, "Expired Password"
  122.                             DoCmd.OpenForm "frm_change_password", acNormal
  123.                         Else
  124.                             DoCmd.OpenForm "switchboard"
  125.                         End If
  126.                 Case Else
  127.                         strmsg = " Access Denied" & _
  128.                                     vbCrLf & " Contact your Administrator if the problem persists.   "
  129.                         MsgBox strmsg, vbInformation, "INVALID USER ID or PASSWORD"
  130.             End Select
  131.  
  132. End Select
  133.  
  134. exit_display_menu:
  135.     Exit Sub
  136.  
  137. err_display_menu:
  138.     MsgBox Err.decsription
  139.     Resume exit_display_menu
  140.  
  141. End Sub
  142.  
  143.  
  144.  
  145.  
  146.  
  147.  
  148. ' ***********************************************************
  149. '   Form: frm_main
  150. '
  151. '   Function :  login screen
  152. '
  153. '   Date last Modified : 26/02/2007
  154. '   26/02/2007 - redesign for Sydney use. Sydney's menu now in a
  155. '                      switchboard format
  156. '
  157. ' ***********************************************************
  158.  
  159. Option Compare Database
  160. Option Explicit
  161. Private intLogonAttempts As Integer
  162.  
  163. ' ******************************************************
  164. ' close form
  165. ' ******************************************************
  166. Private Sub close_form_Click()
  167. On Error GoTo Err_close_form_Click
  168.  
  169.     DoCmd.RunMacro "macro_exit"
  170.  
  171. Exit_close_form_Click:
  172.     Exit Sub
  173.  
  174. Err_close_form_Click:
  175.     MsgBox Err.Description
  176.     Resume Exit_close_form_Click
  177. End Sub
  178.  
  179. ' ***********************************************************
  180. '   User has entered user_id and Password
  181. ' ***********************************************************
  182. Private Sub cmdOK_Click()
  183. On Error GoTo Err_cmdOK_Click
  184.  
  185.     ' Validate User ID and Password and then display menu items
  186.       display_menu
  187.  
  188. Exit_cmdOK_Click:
  189.     Exit Sub
  190.  
  191. Err_cmdOK_Click:
  192.     MsgBox Err.Description
  193.     Resume Exit_cmdOK_Click
  194. End Sub
  195.  
  196. ' ******************************************************
  197. ' maximize the screen
  198. ' ******************************************************
  199. Private Sub Form_Load()
  200. On Error GoTo Err_Form_Load
  201.  
  202.     DoCmd.Maximize
  203.  
  204. Exit_Form_Load:
  205.     Exit Sub
  206.  
  207. Err_Form_Load:
  208.     MsgBox Err.Description
  209.     Resume Exit_Form_Load
  210.  
  211. End Sub
  212.  
  213. Private Sub Form_Open(Cancel As Integer)
  214.  
  215. 'Reset Logon attempts on open form
  216. intLogonAttempts = 0
  217.  
  218. End Sub
  219.  
  220. ' ********************************************************************************
  221. ' when the user id gets the focus, the user id and password are reset to blank   *
  222. ' ********************************************************************************
  223.  
  224. Private Sub user_id_GotFocus()
  225. On Error GoTo Err_user_id_GotFocus
  226.  
  227.     'remove current user and password
  228.     Me!user_id = Null
  229.     Me!password = Null
  230.  
  231. Exit_user_id_GotFocus:
  232.     Exit Sub
  233.  
  234. Err_user_id_GotFocus:
  235.     MsgBox Err.Description
  236.     Resume Exit_user_id_GotFocus
  237. End Sub
Mar 16 '08 #1
6 2568
NeoPa
32,584 Recognized Expert Moderator MVP
Please visit this thread to see why we would rather you didn't double-post (Please do Not Double Post).

Admin.
Mar 16 '08 #2
NeoPa
32,584 Recognized Expert Moderator MVP
Tom, your question needs to be more specific.
Your code needs to be far more targetted.

You need to say what is not working and where in your code this problem occurs.

Whatever communication you have with anyone, don't assume they have read all of your code. It is quite unreasonable to expect anyone to go to that much truble (237 lines of code) for you for free.

I'll leave this with you for now.
Mar 16 '08 #3
Tomino
9 New Member
Your right, it's a bit tomuch code to read through ;-)

I look up a value in field [Attempts] out of table tbl_user with Dlookup and put it in var. intLogonAttempt s


intLogonAttempt s =

value of the looked up field [Attempts] need to be raised by 1:
Expand|Select|Wrap|Line Numbers
  1. DLookup("[Attempts]", "tbl_users", "user_id=forms!frm_main!user_id")
  2.  
  3. intLogonAttempts = intLogonAttempts + 1
After 3 failed logon attempts, the user needs to be locked:
Expand|Select|Wrap|Line Numbers
  1. If intLogonAttempts > 3 Then
  2.                 MsgBox "You are locked out this database.  Please contact your System Administrator.", vbCritical, "Restricted Access!"
  3.                 bln_lock = True
The problem is I can't write the new value of intlogAttempts (intlogAttempts + 1) to the existing field value.

I want to write intlogonAttempt s + 1 to the field [Attempts] of user: [DLookup("[Attempts]", "tbl_users" , "user_id=forms! frm_main!user_i d")] so after 3 failed log in attempts, the user is locked out by changing value of field loclout of the user who tried to log in:
Expand|Select|Wrap|Line Numbers
  1. 'write intlogonAttempt to [Attempts] in tbl_users
  2.  
  3.             If intLogonAttempts > 3 Then
  4.                 MsgBox "You are locked out this database.  Please contact your System Administrator.", vbCritical, "Restricted Access!"
  5.                 bln_lock = True
  6.                 'Application.Quit
  7.             End If
Thank you very much for your help,

Regards,
Tom
Mar 16 '08 #4
Tomino
9 New Member
Hello,

I made a login form in Access using some code I found on the net. I would like the database to keep track of every failed log attempt per user and to lock the user after 3 failed log in attempts.
With recordsset I want to search in tbl_users how many failed attempts the user did to get in the database so I created in "tbl_users" a field called "Attempts" to keep track of every failed log in into the database.

here is the code:

Expand|Select|Wrap|Line Numbers
  1. ' ' Module   : mod_display_menu
  2. ' Function : display the switchboard after checking the access and password and password expiry date
  3.  
  4. Option Compare Database
  5. Option Explicit
  6. Dim rsUsers As Object
  7. Dim dbLimsFreeze As Object
  8. Dim fldEnum As Object
  9. Dim fldColumns As Object
  10.  
  11.  
  12. Sub display_menu()
  13. On Error GoTo err_display_menu
  14.  
  15.  
  16.  
  17. ' *         Validate password                                                    *
  18.  
  19.  
  20. If valid_user = 2 Then
  21.    check_password = DLookup("[passwords]", "tbl_users", "user_id=forms!frm_main!user_id")
  22.    If check_password = Forms!frm_main!password Then
  23.         valid_user = 2
  24.    Else
  25.         valid_user = 1
  26.    End If
  27.  
  28. End If
  29.  
  30.  
  31.  
  32. ' **********************************************
  33. ' *         Validate access_level              *
  34. ' **********************************************
  35. If valid_user = 2 Then
  36.     access_level = DLookup("[access_level]", "tbl_users", "user_id=forms!frm_main!user_id")
  37. End If
  38.  
  39. Select Case valid_user
  40.  
  41.     Case 0, 1
  42.             strmsg = " Access Denied" & _
  43.                         vbCrLf & " Contact your Administrator if the problem persists.   "
  44.             MsgBox strmsg, vbCritical, "INVALID USER ID or PASSWORD"
  45.  
  46.             Set dbLimsFreeze = CurrentDb
  47.             Set rsUsers = dbLimsFreeze.OpenRecordset("tbl_users")
  48.             Set fldColumns = rsUsers.Fields
  49.  
  50.             ' Scan the records from beginning to each
  51.             While Not rsUsers.EOF
  52.             ' Check the current column
  53.             For Each fldEnum In rsUsers.Fields
  54.             ' If the column is named "Attempts"
  55.             If fldEnum.Name = "Attempts" Then
  56.             ' If the title of the current record is "user_id=forms!frm_main!user_id"
  57.                 If fldEnum.Value = "user_id=forms!frm_main!user_id" Then
  58.             ' then change its value
  59.                     rsUsers.Edit
  60.                     rsUsers("Attempts").Value = +1
  61.                     rsUsers.Update
  62.                 End If
  63.             End If
  64.         Next
  65.             ' Move to the next record and continue the same approach
  66.         rsUsers.MoveNext
  67.     Wend
  68.  
  69.  
  70.             If rsUsers("Attempts").Value > 100 Then
  71.                 MsgBox "You are locked out this database.  Please contact your System Administrator.", vbCritical, "Restricted Access!"
  72.                 bln_lock = True
  73.                 'Application.Quit
  74.             End If
Mar 17 '08 #5
NeoPa
32,584 Recognized Expert Moderator MVP
Tom, I don't know where you're going with the last post (#5). It seems little different from the first, except there are fewer lines. The question still implies it is the task of the expert to sort through all of your code, without any pointers from you, to determine your not very precisely specified problem.

Your earlier post (#4) is better, but still doesn't specify any line numbers of the code to indicate what you've tried, so we can see where you may be going wrong. It's very difficult to help someone if they don't explain their problem clearly.

As the question is so broad, all I can do is explain how you would update a value in a table if the form is not bound to that table.

That would be to create and execute some SQL of the form :
Expand|Select|Wrap|Line Numbers
  1. strSQL = "UPDATE [YourTable] " & _
  2.          "SET [YourCount]=[YourCount]+1 " & _
  3.          "WHERE [KeyField]='{Logon Name}'"
'{Logon Name}' is used here and is a string literal. You may well want to replace this with a reference to a form control (Me.UserName for instance). If so use instead :
Expand|Select|Wrap|Line Numbers
  1. strSQL = "UPDATE [YourTable] " & _
  2.          "SET [YourCount]=[YourCount]+1 " & _
  3.          "WHERE [KeyField]='" & Me.UserName & "'"
Mar 17 '08 #6
NeoPa
32,584 Recognized Expert Moderator MVP
I left out the code for running the SQL. That would come after whichever of the other two bits of code you chose, and would be :
Expand|Select|Wrap|Line Numbers
  1. Call DoCmd.RunSQL(strSQL)
Mar 17 '08 #7

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

Similar topics

13
40791
by: Dan R Brown | last post by:
I have a large form that is generated dynamically in a jsp using xml / xslt. So, to break up this form into several "tabbed" sections, I break up the form using <div> tags. Each <div style="display:none"> can be displayed by setting the style attribute to "display:", or hidden with "display:none". This gives the illusion that the person filling out the form is switching from page to page...without the overhead of extra hits on the server,...
5
4617
by: Tyler Style | last post by:
Hullo - looking for a little advice here. I have a form on a page in one domain submitting to a cgi in another domain. Weirdly, on some Windows XP systems, a form on the page fails to submit/post properly to the cgi and users get the message from IE that it "Cannot find server: The page cannot be displayed The page you are looking for is currently unavailable. The Web site might be experiencing technical difficulties, or you may need to...
1
1264
by: Eric | last post by:
Couple of general webform questions. Most are about html code created/managed by the editor. I work in GridLayout Mode. 1. Is there a reference or guideline for how the html should appear when viewing a web form in HTML format, after you've added elements in design view? Can I change they way they are formatted for viewing? 2. What's the easist way to clone a webform while inside a project. I don't want to inherit from it, I just want...
3
1338
by: The One | last post by:
Have created a form to pop up with 2 option I then wish to write the text that is in the option button chose back to the original form using the code below but it gives me an exception error so could any please help me. Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim frm As Form1 Dim text As String
4
4196
by: Baz | last post by:
Hi. I'm new to this VB.Net mullarkey, and I must say it is proving to be a very trying experience. Here is the latest in a long line of problems: The Scenario ========= I am building an MDI application. The first thing it does is to pop up a little logon form which gathers and authenticates an SQL Server
2
3498
by: NishSF | last post by:
Would anyone have any suggestions/javascript code so that if one clicks the Radio Button "Yes" below he has the option of selecting any of the six CheckBox below. If the user clicks on Radio Button "No", he should not have the option of clicking on any of the six checkboxes. See Code attached. Thank you so much in advance for your help as I can't get to make this combo work. <p>Did you have any problems finding any of the information...
4
8515
by: crystal | last post by:
I've checked the threads but haven't been able to come up with a solution to my issue. Help...... I have a simple form based on a table. Within the form is a subform that is also, through a Q, based on the same table. The code: Private Sub Select_BeforeUpdate(Cancel As Integer) On Error GoTo resetselect_Err
18
3120
by: sweeneye | last post by:
Hi, I'm basing a query on the variables used in a form. The database contains lots of problems, say with a computer and a tick box for the apropriate component like monitor, keyboard, mouse etc. and each has several eg problem 1 has a monitor and mouse problem My form then has what to look for tick boxes (tri-state) for each of these. I want my query to include all monitor problems when that is ticked and all monitor and mouse problems...
6
2202
by: shapper | last post by:
Hello, I am creating a form that includes a few JQuery scripts and TinyMCE Editor: http://www.27lamps.com/Beta/Form/Form.html I am having a few problems with my CSS: 1. Restyling the Select
16
2761
by: Steve | last post by:
I am working on a database that has a main menu, many sub-menus and some sub-sub-menus. They are all forms that have numerous command buttons on them to open forms and reports in the database. The database has hundreds of forms and reports. I was asked to go through all the menu forms and determine if all the buttons worked, if there were any problems when either the form or report opened and to come up with a list of the forms and reports...
0
9942
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9792
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
11142
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10847
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
7971
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
7129
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5991
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
4220
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3233
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.