Password lock after 5 attempts

Asked

Viewed 158 times

0

I created the routine that counts number of user attempts when logging into the system, if it misses the password for five times the system blocks the user. However my code is not taking into account the user code (login access), that is, always putting different users in the five attempts, in the fifth attempt the system will block the user who was last tried. I put in the table 'users' the column 'attempt', but it keeps counting + 1 even changing the user login. Someone can help?

--variável
Private fiContador As Integer

--código
Private Sub cmdEntrar_Click()

If txtSenha.Text <> lTBUsuarios("senha") Then  'Rotina que conta as tentativas de login

lsql = ("SELECT tentativa FROM usuarios WHERE id_usuario = " & txtLogin.Text)
MsgBox lsql

    fiContador = fiContador + 1
        If lTBUsuarios("tentativa") >= 5 Then
            MensagemErro "O usuário foi inativado."
                txtLogin.SetFocus

            lsql = "UPDATE USUARIOS SET status = '" & "INATIVO" & "', tentativa = '" & "0" & "' WHERE id_usuario = " & txtLogin.Text & ""
                gBDSistemaIntegrado.Execute lsql
        Else
            'fazer 1, 2, 3, 4, e 5 if vendo quantos registros de tentativa tem para o usuário
            'em cada um deles colocar o valor do fiContador = 1, 2, 3, 4,  ou 5

            lsql = "UPDATE USUARIOS SET tentativa = '" & fiContador & "' WHERE id_usuario = " & txtLogin.Text & ""
                gBDSistemaIntegrado.Execute lsql

            MensagemErro "Senha inválida. Tentativa " & fiContador & " de 5."
                    txtSenha.Text = ""
                    txtSenha.SetFocus

            Exit Sub
        End If
    Exit Sub
End If
  • 2

    I edited it now, look.

  • now only missing the part that picks up the binder of that user, and not the variable that counts for all.

  • I couldn’t put this part together, the logic I have, I just can’t apply in code practice.

  • Before the line "endConnector = endConnector + 1" you need to make a SELECT attempt FROM usuarios WHERE id_usuario = txtLogin.Text and save the value in binder, which is to take that person’s counter, and increase one in it. and not in the previous attempt. thus, the ficontador + 1 will be increasing the previous only of that person.

  • lsql = ("SELECT try FROM usuarios WHERE id_usuario = " & txtLogin.Text)

  • that, and have to save the return in binder. on the line just before the ficontador = ficontador + 1

  • I made the select, now as I save the counter to pick only that person?

  • just save the return of the query in binder, the same way you take password and other things. Otherwise I think you do not need to touch anything else

  • Yeah, I can’t make this comeback in this case here...

  • Well, you need to execute him, and see how he picks up the return. I do not use VB, you need to see how you do with other things (like catch password), the syntax is the same. See another select how it is done. In place of msxbox you give the Run and take the value in some way with fiContator = somethingField(1) or something like that. I suppose there are other places in your code where you take back select, to see the correct syntax.

  • fiContactor = lTBUsuarios.Fields("attempt"). Value 'Routine that holds the logged-in user’s 'attempt' variable

  • Tested and worked, thank you very much for the trick....

  • It would be nice for you to post the solved code in the field below, of responses, and mark as solved by clicking on the green V next to the voting arrows. Thus, it can serve as a reference for other website colleagues.

  • Trading post........

Show 9 more comments

1 answer

1

If txtSenha.Text <> lTBUsuarios("senha") Then  'Rotina que conta as tentativas de login
    'lsql = ("SELECT tentativa FROM usuarios WHERE id_usuario = " & txtLogin.Text)

    gsFiContador = lTBUsuarios.Fields("tentativa").Value  'Rotina que guarda variável 'tentativa' do usuário
    gsFiContador = gsFiContador + 1

    'MsgBox gsFiContador

        If lTBUsuarios("tentativa") >= 5 Then
            MensagemErro "O usuário excedeu número de tentativas e está inativo. Contate o administrador do sistema."
                txtLogin.SetFocus

            lsql = "UPDATE USUARIOS SET status = '" & "INATIVO" & "', tentativa = '" & "0" & "' WHERE id_usuario = " & txtLogin.Text & ""
                gBDSistemaIntegrado.Execute lsql
        Else
            lsql = "UPDATE USUARIOS SET tentativa = '" & gsFiContador & "' WHERE id_usuario = " & txtLogin.Text & ""
                gBDSistemaIntegrado.Execute lsql

            MensagemErro "Senha inválida. Tentativa " & gsFiContador & " de 5."
                    txtSenha.Text = ""
                    txtSenha.SetFocus
            Exit Sub
        End If
    Exit Sub
End If
  • Even better, it took advantage of the previous select. If you want to increment, you can put SELECT name, password, trial + 1 FROM... and even take the line of sum one, OR in update do SET try = try + 1. But are only possibilities, of course.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.