Encodes a source character string and returnsthe encoded character string result.
Syntax
- expression
- An expression that results in a character string value. If youuse a constant, you must enclose it in quotation marks (" ").
Example
Thisprocedure uses the ENCODE function to disguise a password that the userenters, and then displays the encoded password:
r-encode.p
DEFINE VARIABLE password AS CHARACTER NO-UNDO FORMAT "x(16)".DEFINE VARIABLE id AS CHARACTER NO-UNDO FORMAT "x(12)".DEFINE VARIABLE n-coded-p-wrd AS CHARACTER NO-UNDO FORMAT "x(16)".SET id LABEL "Enter user id" password LABEL "Enter password" BLANK WITH CENTERED SIDE-LABELS.n-coded-p-wrd = ENCODE(password).DISPLAY n-coded-p-wrd LABEL "Encoded password".
Notes
- Youcan use the ENCODE function to encode a string that contains double-bytecharacters.
- The ENCODE function performs a one-way encoding operation that youcannot reverse. It is useful for storing scrambled copies of passwords ina database. It is impossible to determine the original passwordby examining the database. However, a procedure can prompt a userfor a password, encode it, and compare the result with the stored,encoded password to determine if the user supplied the correct password.
- In order to ensure reliable results, the original encoding andany subsequent encoded comparisons must run in the same code page.In environments with multiple code pages, Progress Software Corporation strongly recommendsthat programs use the CODEPAGE-CONVERT function so that occurrencesof the ENCODE function related to the same strings run in the samecode page.
- The output of the ENCODE function is 16 characters long. Makesure the target field size is at least 16 characters long.