March 4, 2021
Hot Topics:

Access Denied!

  • By Karl Moore
  • Send Email »
  • More Articles »

Password protect your PC with help from the VB Voice!

First off, let's get a few facts straight. When it comes down to computer security, the world is under some kind of delusion. Every hacker film I watch seems to contain a spotty teenager attempting to break into the world's most powerful computer.

Err, by the way, that same computer also hosts the world's mostuser-friendly interface. Gee, that's lucky - if the audience saw a real-lifegreen ol' mainframe screen, viewer numbers would rapidly decrease.

And why does he ALWAYS manage to guess the password on his third and final sweat-breaking try? Sheesh!

In this short section, we'll be creating our own mini-security program utilising a combination of techniques we've already learned and a couple we've yet to explore.

Open Visual Basic and create a new Standard Exe. Change the Form1 Name property to "frmLogon" and its caption to "Enter your Password". Create a text box and change its Name property to "txtPassword", its PasswordChar property to an asterisk "*" and remove everything from its Text property.

Now add a command button to the form. Change its Name property to "cmdLogon" and its Caption to "Logon". Your form should look like this:

Now let's start coding. Firstly, we need to declare a variable to hold the number of times a user has attempted to enter a password.

Don't forget - to declare a variable, open the code window and move to the (Declarations) section. For instance, you could double click on a blank area of the form and then select (General) from the object drop-down box and (Declarations) from the procedure drop-down box.

Declare as follows:

Dim LoginCount as Integer
Now in the Click procedure of cmdLogon, enter the following code. You don't need to type in my notes, which begin with the comment symbol - ' - these are to help you understand the code.
LoginCount = LoginCount + 1' Increment the variable by oneIf LoginCount > 3 ThenMsgBox "No more tries, you HACKER!"Exit SubEnd If' The above is "conditional logic"' You're saying if the LoginCount variable is greater' than three - in other words, if they've attempted to ' log on more than three times - then tell them where to' go! Exit Sub just stops the code running right' there, ignoring the rest of our procedureIf txtPassword.Text = "TOPSECRET" ThenMsgBox "Password correct! Access granted..."ElseMsgBox "Password incorrect!"End If' The above is another example of conditional logic.' It checks to see if the textbox text is equal to "TOPSECRET". ' If it is, it congratulates them - otherwise it warns them!

Try running the application. It should allow you to attempt an artificial logon. If the password you supply is correct, it will praise you. If not, err, it won't. If you try checking after three times, the procedure gets angry and ignores your request.

Ahh, the power of programming!

Page 4 of 5

This article was originally published on November 4, 2002

Enterprise Development Update

Don't miss an article. Subscribe to our newsletter below.

Thanks for your registration, follow us on our social networks to keep up-to-date