Function AX_SetPass() Professional

Sets the password used for encryption/decryption operations.

Syntax
AX_SetPass( <cPassword> ) --> lSuccess
Parameters
<cPassword>
In <cPassword> the character string is stored which represents the chosen password. Note that the string may only be up to eight characters long and that it is case-sensitive. This means that "HOBBIT" is interpreted as a different password than "Hobbit".
Passing an empty string ( "" ) to the function clears the password.
Return

The function returns a logical value indicating whether the password is successfully set ( .T. ) or if the operation failed ( .F. ). A failed operation causes an error code that can be retrieved via the :getLastError() method of the DacSession object.

Description

To initiate encryption and decryption in the current workarea, a single call to AX_SetPass() should be made.

After the password is successfully set, all new records appended or updated are encrypted before are stored.

Note that if a file has been encrypted without a prior call to AX_SetPass(), it also needs to be decrypted without a call of this function. If no password has been set, eight ASCII 0's are used for encryption and decryption.

To assure that the password is not easy accessible at runtime, it is stored in an encrypted form in memory.

when a file is accidentally decrypted with a wrong password, the following steps are required to decrypt it properly:

1. Re-encrypt the table with the WRONG password. (Put it back to its former state.)

2. Set the CORRECT password.

3. Now decrypt the file with the CORRECT password.

Examples
#include "ads.ch" 


// Install ADSDBE as default database engine. 
PROCEDURE DbeSys 
   IF !DbeLoad( "ADSDBE" ) 
      Alert( "ADSDBE could not be installed!" ) 
   ENDIF 
   DbeSetDefault( "ADSDBE" ) 
RETURN 


PROCEDURE Main 
   // Connect to database server. 
   LOCAL cConnect := "DBE=ADSDBE;SERVER=\\ALASKA\VOL1" 
   LOCAL oSession := DacSession():new( cConnect ) 

   IF .NOT. oSession:isConnected() 
      Alert( "Connection to server could not be established!" ) 
      QUIT 
   ENDIF 

   // Open TEST.DBF, set a password for this workarea and 
   // encrypt the table. 
   USE Test NEW EXCLUSIVE 
   AX_SetPass( "Hobbit" ) 

   IF AX_DBFEncrypt() 
      ? "Encryption ok." 
   ELSE 
      ? "Encryption FAILED!" 
   ENDIF 

   // Close databases and disconnect from server. 
   DbCloseAll() 
   oSession:disconnect() 
RETURN 
Feedback

If you see anything in the documentation that is not correct, does not match your experience with the particular feature or requires further clarification, please use this form to report a documentation issue.