PDA

View Full Version : Password Expiry - 3 Strikes Then Out



niailmar
2012-07-25, 12:00 AM
Hello,

I need an expert to solve my problem.

I have login userform, which when user key in wrong password (3 times in a rows), a message will appear and close login userform.

Here the code of enter button:



Private Sub EnterPassword_Click()

Dim password As StringDim x As Integerpassword = PasswordInput.TextIf password = WorksheetFunction.VLookup(UserList.Value, Range("Users_List"), 2, 0) ThenMsgBox "Password Accepted"Unload MeWorksheets("PCList").Visible = xlSheetVisibleSheets("PCList").SelectWorksheets("Main Page").Visible = xlSheetVeryHiddenActiveSheet.Range("$A$9:$K$1048576").AutoFilter Field:=11Worksheets("Blank").Visible = xlSheetVeryHiddenElse For x = 1 To 3If x < 3 ThenMsgBox "Unsuccessfull!"Next x ElseIf x = 3 ThenMsgBox "Sorry, 3 strikes you're out.", 16, "Cannot continue; incorrect password not given."End IfExit SubEnd If
End Sub

I attach an interface of login form for your references.
I appreciate your help on this.

Thanks a lot. http://www.excelforum.com/attachment.php?attachmentid=169054&d=1342692981

nevadaDave
2012-07-25, 06:18 PM
Can't download your attachment

niailmar
2012-07-26, 04:17 PM
Can't download your attachment

I'm sorry. It's not an attachment but just link to view the image :)

nevadaDave
2012-07-26, 06:19 PM
Option Explicit
Public x As Integer


Private Sub loginUserForm_Initialize()
x = 1
enterPassword.Caption = "Enter Password, " & x
End Sub


Private Sub enterPassword_Click()


Dim password As String
password = PasswordInput.Text
If password = WorksheetFunction.VLookup(UserList.Value, Range("Users_List"), 2, 0) Then
MsgBox "Password Accepted"
Unload Me
Worksheets("PCList").Visible = xlSheetVisible
Sheets("PCList").Select
Worksheets("Main Page").Visible = xlSheetVeryHidden
ActiveSheet.Range("$A$9:$K$1048576").AutoFilter Field:=11
Worksheets("Blank").Visible = xlSheetVeryHidden
Else:
If x < 3 Then
MsgBox "Unsuccessfull" & "try number " & x
x = x + 1
enterPassword.Caption = "Enter Password, " & x
PasswordInput.Text = ""
ElseIf x = 3 Then
MsgBox "Sorry, 3 strikes you're out.", 16, "Cannot continue; incorrect password not given."
Me.Hide
Unload Me
End If
Exit Sub
End If
End Sub