Option Explicit
Const T As String = "Bienvenue"
'Convention des noms !!!
'Cmd = CommandButton
'Txb = TextBox
'Cbx = CheckBox
Private Sub Cmd_sortie_CLICK_Click()
Unload Me
End Sub
Private Sub UserForm_Initialize()
ThisWorkbook.Activate
Dim WS As Worksheet
With Me
.Caption = T
.Txb_Pwd_Util.PasswordChar = "*"
End With
'For Each WS In Worksheets
'If WS.Name <> "Interface" Then
'WS.Visible = xlSheetVeryHidden
' End If
'Next
UserForm1.Lst_id.RowSource = "MDP!A2:A25"
End Sub
Private Sub UserForm_Activate()
Me.Lst_id.SetFocus
End Sub
Public Sub Cmd_Ok_Btn_Click()
Dim Rech As Range
Dim monparametre As Byte
Static TentativePW As Byte, TentativeID As Byte
Sheets("parametre").Range("A6").Value = Me.Lst_id
If Lst_id = Empty Then End
With ThisWorkbook.Worksheets("MDP").Range("a1:a500")
Set Rech = .Range("users").Find(Lst_id, LookIn:=xlValues, lookat:=xlWhole)
If Not Rech Is Nothing Then
If Txb_Pwd_Util = Rech.Offset(0, 1) Then
If Me.Cbx_Change_PW = True Then
MaSecondeMacro Me.Lst_id
Else
monparametre = Rech.Offset(0, 2)
If monparametre = 1 Then
Accueil1.Show
Unload Me
ElseIf monparametre = 3 Then
Employés.Show
Unload Me
End If
End If
Else
TentativePW = TentativePW + 1
If TentativePW > 3 Then ThisWorkbook.Close 0
MsgBox "Mot de passe invalide, Tentative N° " & TentativePW & " Sur 3", vbCritical, T
With Me.Txb_Pwd_Util
.Value = ""
.SetFocus
End With
End If
Else
TentativeID = TentativeID + 1
If TentativeID > 3 Then ThisWorkbook.Close 0
MsgBox "Utilisateur inconnu, , Tentative N° " & TentativeID & " Sur 3", vbCritical, T
End If
End With
End Sub
Private Sub MaSecondeMacro(User As String)
Dim Message As Byte
Dim Rech As Range
Set Rech = Range("Users").Find(Lst_id, LookIn:=xlValues, lookat:=xlWhole)
If Me.Cbx_Change_PW = True Then
ChangePW User, Rech
Exit Sub
End If
If (Now - Rech.Offset(0, 3)) > 30 Then
Message = MsgBox("Il apparait que votre password arrive à expiration" & vbCrLf & _
"Voulez vous changer ? ", vbQuestion + vbYesNo, T)
If Message = vbYes Then
ChangePW User, Rech
End If
End If
End Sub
Private Sub ChangePW(User As String, Rech As Range)
With UserForm2
.LblUser = User 'J'utilise des Labels pour passer des arguments
.LblCell.Caption = Rech.Offset(0, 1).Address 'Idem mais sur label caché
.Show
End With
End Sub
Private Sub Cmd_Exit_Click()
Unload Me
End Sub