1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122
|
Option Compare Database
Private Declare Function ShowWindow Lib "user32" (ByVal hWnd As Long, ByVal nCmdShow As Long) As Long
Private Const giMaxLogin As Byte = 3 'nombre maxi autorisé de tentative de connexion
Private Sub BoutonUtilisateur_Click()
Me.Password = LCase$(Nz(Password))
On Error GoTo errortag
Dim oDb As DAO.Database
Dim rst As DAO.Recordset
Dim sSql As String
Dim bBadLogin As Boolean, bClose As Boolean
Static i As Byte
i = i + 1 'incrémente les tentatives
If IsNull(Me.Login) Or IsNull(Me.Password) Then
bBadLogin = True
Else
Set oDb = CurrentDb
' Cherche l'utilisateur dans la table, en sachant que login ne peut contenir le caractère <'> ni <">
sSql = "SELECT * FROM Personnel WHERE Utilisateur = true AND Nom = '" & Me.Login & "'"
Set rst = oDb.OpenRecordset(sSql, dbOpenSnapshot)
If Not rst.EOF Then
' Vérifier que le mot de passe est égal au mot de passe saisie crypté
If rst("password") = Me.Password Then 'Mot de passe ok
i = 0
bBadLogin = False
Else 'Mot de passe incorrect
bBadLogin = True
Me.Password.SetFocus
Me.Password.ForeColor = vbRed
End If
Else ' pas de login trouvé
bBadLogin = True
End If
End If
If bBadLogin = True Then 'si tentative mauvaise
If i < giMaxLogin Then 'si nb tentative < au maxi
MsgBox "NOM D'UTILISATEUR OU MOT DE PASSE ERRONE" & vbCrLf & "IL VOUS RESTE " & (giMaxLogin - i) & " TENTATIVE(S) DE CONNECTION"
Else 'si nb tentative >= maxi => on ferme
MsgBox "VOUS AVEZ DEPASSE LE NOMBRE DE TENTATIVES AUTORISEES !"
DoCmd.Quit
'bClose = True
End If
End If
Fin:
Set rst = Nothing
Set oDb = Nothing
If bBadLogin = False Then
DoCmd.OpenForm "Identite", , , , , , "Connexion"
DoCmd.SelectObject acForm, Me.Name, False
DoCmd.OpenForm "MenuPrincipal"
DoCmd.Close acForm, Me.Name
ElseIf bClose = True Then
DoCmd.Close acForm, Me.Name
End If
Exit Sub
errortag:
End Sub
Private Sub BoutonResponsable_Click()
Me.Password = LCase$(Nz(Password))
On Error GoTo errortag
Dim oDb As DAO.Database
Dim rst As DAO.Recordset
Dim sSql As String
Dim bBadLogin As Boolean, bClose As Boolean
Static i As Byte
i = i + 1 'incrémente les tentatives
If IsNull(Me.Login) Or IsNull(Me.Password) Then
bBadLogin = True
Else
Set oDb = CurrentDb
' Cherche l'utilisateur dans la table, en sachant que login ne peut contenir le caractère <'> ni <">
sSql = "SELECT * FROM Personnel WHERE Responsable = true AND Nom = '" & Me.Login & "'"
Set rst = oDb.OpenRecordset(sSql, dbOpenSnapshot)
If Not rst.EOF Then
' Vérifier que le mot de passe est égal au mot de passe saisie crypté
If rst("password") = Me.Password Then 'Mot de passe ok
i = 0
bBadLogin = False
Else 'Mot de passe incorrect
bBadLogin = True
Me.Password.SetFocus
Me.Password.ForeColor = vbRed
End If
Else ' pas de login trouvé
bBadLogin = True
End If
End If
If bBadLogin = True Then 'si tentative mauvaise
If i < giMaxLogin Then 'si nb tentative < au maxi
MsgBox "NOM D'UTILISATEUR OU MOT DE PASSE ERRONE" & vbCrLf & "IL VOUS RESTE " & (giMaxLogin - i) & " TENTATIVE(S) DE CONNECTION"
Else 'si nb tentative >= maxi => on ferme
MsgBox "VOUS AVEZ DEPASSE LE NOMBRE DE TENTATIVES AUTORISEES !"
DoCmd.Quit
'bClose = True
End If
End If
Fin:
Set rst = Nothing
Set oDb = Nothing
If bBadLogin = False Then
DoCmd.OpenForm "Identite", , , , , , "Connexion"
DoCmd.SelectObject acForm, Me.Name, False
DoCmd.OpenForm "Responsables"
DoCmd.Close acForm, Me.Name
ElseIf bClose = True Then
DoCmd.Close acForm, Me.Name
End If
Exit Sub
errortag:
End Sub |
Partager