Results 1 to 6 of 6

Thread: [RESOLVED] password problem

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Feb 2007
    Location
    Malaysia
    Posts
    1,370

    Resolved [RESOLVED] password problem

    I have a problem.Actually I want to set a counter that allow the user to enter the valid password for 3 times.. if the password fail after 3 times attempt, the form 1 show.How to do that?


    Code:
    Set adoConn = New ADODB.Connection
        Set adoRS = New ADODB.Recordset
    
        Dim cs As String
            cs = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\AdminPassword.mdb" & ";Persist Security Info=False;"
    
        adoConn.ConnectionString = cs
        adoConn.Open
    
    If Text2.Text = "" Then
    
            MsgBox "Sila masukkan Kata laluan Anda", vbCritical, "Kata laluan"
          '  MsgBox "Sila masukkan Kata laluan Anda"
            Text2.Text = ""
            Text2.SetFocus
        Else
        
         usrnm = Text2.Text
         adoRS.Open "SELECT * FROM pass WHERE password='" & usrnm & "';", adoConn, adOpenStatic, adLockOptimistic
            
       
            
         If adoRS.Fields("Password").Value = Text2.Text Then
            pass = True
            'if password valid, success
            MsgBox "Anda Berjaya memasuki ruang admin" & vbCrLf & "Logged in. Username: " & usrnm & " !", vbInformation, "Selamat datang"
            Form2.Show
            Unload Me
        Else
        'if password invalid,message box ask to insert invalid password
             MsgBox "Kata laluang tidah sah. Ruang ini hanya untuk admin", vbCritical, "WARNING"
             'Exit Sub
             Unload Me
             Form1.Show
        
    
            Exit Sub
        End If
     End If
    End Sub

  2. #2
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: password problem

    Something like
    vb Code:
    1. Dim intCounter As Integer
    2. Set adoConn = New ADODB.Connection
    3.     Set adoRS = New ADODB.Recordset
    4.  
    5.     Dim cs As String
    6.         cs = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\AdminPassword.mdb" & ";Persist Security Info=False;"
    7.  
    8.     adoConn.ConnectionString = cs
    9.     adoConn.Open
    10.  
    11. If Text2.Text = "" Then
    12.  
    13.         MsgBox "Sila masukkan Kata laluan Anda", vbCritical, "Kata laluan"
    14.       '  MsgBox "Sila masukkan Kata laluan Anda"
    15.         Text2.Text = ""
    16.         Text2.SetFocus
    17.     Else
    18.    
    19.      usrnm = Text2.Text
    20.      adoRS.Open "SELECT password FROM pass WHERE password='" & usrnm & "';", adoConn, adOpenStatic
    21.      If adoRS.Fields("Password").Value = Text2.Text Then
    22.         pass = True
    23.         'if password valid, success
    24.         MsgBox "Anda Berjaya memasuki ruang admin" & vbCrLf & "Logged in. Username: " & usrnm & " !", vbInformation, "Selamat datang"
    25.         Form2.Show
    26.      Else
    27.         intCounter = intCounter + 1
    28.            If intCounter = 3 Then
    29.               Form1.Show
    30.            Else
    31.               Msgbox "Invalid Password"
    32.            End If
    33.      End If

  3. #3

    Thread Starter
    Frenzied Member
    Join Date
    Feb 2007
    Location
    Malaysia
    Posts
    1,370

    Re: password problem

    The counter value did not change. The value does not increase. It still start with 0 value.

    Code:
    If adoRS.Fields("Password").Value = Text2.Text Then
            pass = True
            'if password valid, success
            MsgBox "Anda Berjaya memasuki ruang admin" & vbCrLf & "Logged in. Username: " & usrnm & " !", vbInformation, "Selamat datang"
            frmmanagement.Show
            Unload Me
            
          Else
             intCounter = intCounter + 1
             
             If intCounter = 3 Then
             frmMenu.Show
             Unload Me
             Else
            'if password invalid,message box ask to insert invalid password
             MsgBox "Invalid password", vbCritical, "WARNING"
             Text2.Text = ""
             Text2.SetFocus
             End If
        End If

  4. #4
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: password problem

    If the first part of your code works (which I did not test) that would tell me the password was valid.

  5. #5

    Thread Starter
    Frenzied Member
    Join Date
    Feb 2007
    Location
    Malaysia
    Posts
    1,370

    Re: password problem

    Yes. But if the password invalid, it go to the second part. at the second part, the user are allow enter the password for 3 times.After 3 attempt,If the password invalid the frmMenu will appear

    Code:
    intCounter = intCounter + 1
             
             If intCounter = 3 Then
             frmMenu.Show
             Unload Me
             Else
            'if password invalid,message box ask to insert invalid password
             MsgBox "Invalid password", vbCritical, "WARNING"
             Text2.Text = ""
             Text2.SetFocus
             End If

  6. #6
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: password problem

    If you are doing this all in a button click, then you are resetting the counter each time you click it. Take Dim intCounter As Integer and move it the forms declaration section and declare it as Private.
    Last edited by Hack; Apr 5th, 2007 at 01:08 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width