473,414 Members | 1,988 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,414 software developers and data experts.

Log in form problems

9
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 2548
NeoPa
32,556 Expert Mod 16PB
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,556 Expert Mod 16PB
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
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. intLogonAttempts


intLogonAttempts =

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 intlogonAttempts + 1 to the field [Attempts] of user: [DLookup("[Attempts]", "tbl_users", "user_id=forms!frm_main!user_id")] 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
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,556 Expert Mod 16PB
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,556 Expert Mod 16PB
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
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...
5
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...
1
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...
3
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...
4
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...
2
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...
4
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,...
18
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....
6
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
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...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
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
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...
0
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
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
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...
0
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...

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.