mobile databases, mobile forms, and mobile synchronization … where you need to work
Providing Pocket Access, Mobile Database, Windows CE Database, and Windows CE Development Solutions

Tip of the Month (May 2008)

Password Protecting Your Form

Built into Visual CE is a simple password protection mechanism for forms. You can build a password into the form and, in order to use the form, the user has to enter the password. You use FORM | PASSWORD to set this up. However, you may want to do more sophisticated password protection, where the user needs to enter a username and password. Here's how to set that up.

You will need a table, PASSWORD, with two columns: USER_NAME and USER_PASSWORD. Create an index on USER_NAME.

Create a form. When asked what database to use, specify "no underlying database". The form will have the following controls:

  • An edit control, connected the @var(10) that the user will use to enter the user name.
  • An edit control, connected the @var(11) that the user will use to enter the password. Starting in version 11 of Visual CE, you can turn on the "Password" property so the value will be hidden while the user types it in. If you have an older version of Visual CE, you can hide the data by setting the text and background colors to be the same.
  • A lookup control. It should look in the PASSWORD table, keyed on @var(10), searching the USER_NAME column. When asked if you want to save the value found, say YES and save the value into @var(12). The value you want to retrieve is USER_PASSWORD. Set the text and background colors to be the same so the password found by the lookup will not be visible to the user.
  • A button that runs the LOGIN macro described below.
  • Turn on Autorecalc for the form (FORM | AUTORECALC).

On your form, you also need a macro to verify the user's identity. Select EDIT | MACROS/EVENTS and create a macro called LOGIN. The macro will have 4 steps:

  1. SKIP: set "Num" to if @var(11) = @var(12) then 2 else 0
  2. Message box: set "Msg" to 'Invalid Password'
  3. Return from macro
  4. Run external: set "Command" to the starting form of your password protected application.

When the form runs, the uer will enter a user name and password and press the LOGIN button. The form will lookup the password for the user in the PASSWORD table and compare it to the one the user entered. If they match, your form will be launched. Otherwise, an error will be displayed.

Previous Tips of the Month