How to Encrypt a Password in FoxPro

Last reviewed: April 29, 1996
Article ID: Q99904
The information in this article applies to:
  • Microsoft FoxPro for Windows, versions 2.5, 2.5a
  • Microsoft FoxPro for MS-DOS, versions 1.02, 2.0, 2.5, 2.5a

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: kbenv kbprg kbcode
KBSubcategory: FxenvMemory


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: April 29, 1996
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.