How to Encrypt a Password in FoxPro

ID: Q99904

2.50 2.50a | 1.02 2.00 2.50 2.50a

WINDOWS    | MS-DOS

The information in this article applies to:

SUMMARY

To encrypt a password so that is not revealed, you can echo asterisks to the screen instead of the actual characters entered.

MORE INFORMATION

The following sample code accepts a four-letter password and echoes four asterisks to the screen. This code must be executed from within a program, not from the Command window.

   CLEAR
   CLEAR ALL
   SET TALK OFF   && Prevents "double" echoing to the screen.
   STORE "" to x  && Initialize memory variable x to character blank.
   @ 2,2 SAY ""   && Position the password GET field on the screen.

   * The following loop sets up the number of characters in the
   * password. It can be modified to be any length.

   FOR y=1 TO 4
      z=INKEY(0)     && Initialize Z to integer value of zero.
      * Add, character by character, each letter of the password typed
      *  in by the user.
      x=x+CHR(z)
      * Echo an * to the GET field on the screen for each letter that
      *  the user types in.
      @ 2,2 SAY REPLICATE("*",y)
      ENDFOR
      ?X  && To display the typed password.

The code above can be modified to reflect a longer password or to echo a different character (other than the "*" character) on the GET field of the screen. If this encryption code is organized as a procedure, the memory variables x, y, and z must be declared as PUBLIC if they are passed into and out of the procedure.

Additional reference words: FoxDos FoxWin 1.02 2.00 2.50 2.50a KBCategory: KBSubcategory: FxenvMemory

Keywords          : kbcode FxenvMemory 
Version           : 2.50 2.50a | 1.02 2.00 2.50 2.50
Platform          : MS-DOS WINDOWS

Last Reviewed: May 22, 1998