Backdoor routine


Posted by Richie on July 24, 2001 12:13 PM

Hi everybody,

I'm writing a routine that will enable selected users to gain access to a program after a number of options have been disabled on start-up, eg the Alt+F11 shortcut to the VBE. (The routine is copied from a Web page - Nathan's Excel Page I think).

What I would like to do is to display in a message box the number of incorrect password attempts made by a user. The problem I am having is that 'attempts' never seems to progress beyond 1. Any ideas? (Sample code follows)

'
' Open the backdoor!
'

' Actions to take place following a keystroke combination of
' ALT+CTRL+SHIFT+ENTER
'
Sub Backdoor()

Application.ScreenUpdating = False

SystemPassword = "letmein"

Message = "Enter the password." ' Set prompt.
Title = "Password verification." ' Set title.
Default = "***" ' Set default.

' Display message, title, and default value.
' Display dialog box at position x, y.
PasswordEntry = InputBox _
(Message, Title, Default, 3500, 2000)

' no password entered
If PasswordEntry = "" Then
Beep
MsgBox "You have not entered a Password." & _
Chr$(10) & Chr$(10) & _
"Please try again.", vbOKOnly + vbCritical, _
"Error - No Password Entered."
End

' incorrect password entered
ElseIf PasswordEntry <> SystemPassword Then
Attempts = Attempts + 1
Beep
MsgBox "You have entered an incorrect Password." & _
Chr$(10) & Chr$(10) & _
"Incorrect attempts so far: " & Attempts _
& Chr$(10), _
vbOKOnly + vbCritical, _
"Error - Incorrect Password."
End

End If

' correct password entered
MsgBox "System Backdoor Successfully Opened.", _
vbOKOnly, "System Development."
Attempts = 0 ' clear incorrect attempts
Application.OnKey "%{F11}" ' re-enable VBE key combo

End Sub

Posted by faster on July 24, 2001 12:21 PM

' Display message, title, and default value. ' Display dialog box at position x, y. PasswordEntry = InputBox _ (Message, Title, Default, 3500, 2000) ' no password entered If PasswordEntry = "" Then Beep MsgBox "You have not entered a Password." & _ Chr$(10) & Chr$(10) & _ "Please try again.", vbOKOnly + vbCritical, _ "Error - No Password Entered." End ' incorrect password entered ElseIf PasswordEntry <> SystemPassword Then Attempts = Attempts + 1 Beep MsgBox "You have entered an incorrect Password." & _ Chr$(10) & Chr$(10) & _ "Incorrect attempts so far: " & Attempts _ & Chr$(10), _ vbOKOnly + vbCritical, _ "Error - Incorrect Password." End End If ' correct password entered MsgBox "System Backdoor Successfully Opened.", _ vbOKOnly, "System Development." Attempts = 0 ' clear incorrect attempts Application.OnKey "%{F11}" ' re-enable VBE key combo

Use a very-hidden sheet to keep track of the number of attempts.
Reset the number on succesful access.

Posted by Ivan F Moala on July 25, 2001 1:51 AM

Your code never gets past 1 because you are ending
the macro and there fore resetting any variables.
You can do as faster suggests and keep it in a
hidden sheet OR loop through your code....ending
it when it does reach 3 attempts.


Ivan

' Display message, title, and default value. ' Display dialog box at position x, y. PasswordEntry = InputBox _ (Message, Title, Default, 3500, 2000) ' no password entered If PasswordEntry = "" Then Beep MsgBox "You have not entered a Password." & _ Chr$(10) & Chr$(10) & _ "Please try again.", vbOKOnly + vbCritical, _ "Error - No Password Entered." End ' incorrect password entered ElseIf PasswordEntry <> SystemPassword Then Attempts = Attempts + 1 Beep MsgBox "You have entered an incorrect Password." & _ Chr$(10) & Chr$(10) & _ "Incorrect attempts so far: " & Attempts _ & Chr$(10), _ vbOKOnly + vbCritical, _ "Error - Incorrect Password." End End If ' correct password entered MsgBox "System Backdoor Successfully Opened.", _ vbOKOnly, "System Development." Attempts = 0 ' clear incorrect attempts Application.OnKey "%{F11}" ' re-enable VBE key combo

Posted by Jerid on July 25, 2001 6:29 AM


Try this

Sub Backdoor()

Dim iAttempts As Integer
Dim SystemPassword As String, PasswordEntry As String
Dim sPromptMessage As String, sPromptTitle As String, sPromptDefault As String
Dim sNoPasswordMsg As String, sNoPasswordTitle As String
Dim sWrongPasswordMsg As String, sWrongPasswordTitle As String
Dim sCorrectPasswordMsg As String, sCorrectPasswordTitle As String

Application.ScreenUpdating = False

SystemPassword = "letmein"
sPromptMessage = "Enter the password." ' Set prompt.
sPromptTitle = "Password verification." ' Set title.
sPromptDefault = "***" ' Set default.

sNoPasswordMsg = "You have not entered a Password."
sNoPasswordMsg = sNoPasswordMsg & vbCrLf & vbCrLf
sNoPasswordMsg = sNoPasswordMsg & "Please try again."

sNoPasswordTitle = "Error - No Password Entered."

sWrongPasswordMsg = "You have entered an incorrect Password."
sWrongPasswordMsg = sWrongPasswordMsg & vbCrLf & vbCrLf
sWrongPasswordMsg = sWrongPasswordMsg & "Incorrect Attempts so far: "

sWrongPasswordTitle = "Error - Incorrect Password."

sCorrectPasswordMsg = "System Backdoor Successfully Opened."
sCorrectPasswordTitle = "System Development."

ShowLoginBox:
If iAttempts < 3 Then
PasswordEntry = InputBox(sPromptMessage, sPromptTitle, sPromptDefault, 3500, 2000)
Else
MsgBox "Good Bye", vbExclamation
Application.ActiveWorkbook.Close False
End If

'No password entered
If PasswordEntry = "" Then
iAttempts = iAttempts + 1
Beep
MsgBox sNoPasswordMsg, vbOKOnly + vbCritical, sNoPasswordTitle
GoTo ShowLoginBox

'Incorrect password entered
ElseIf PasswordEntry <> SystemPassword Then
iAttempts = iAttempts + 1
Beep
MsgBox sWrongPasswordMsg & iAttempts, vbOKOnly + vbCritical, sWrongPasswordTitle
GoTo ShowLoginBox

'Correct password entered
Else
MsgBox sCorrectPasswordMsg, vbOKOnly, sCorrectPasswordTitle
iAttempts = 0
Application.OnKey "%{F11}"
End If

End Sub

Jerid



Posted by Richie on July 25, 2001 10:29 AM