Release 10.1A: OpenEdge Development:
Progress 4GL Reference

> ## ENCODE function

> Encodes a source character string and returns the encoded character string result.

> #### Syntax

>     ENCODE ( expression )

> ``expression``

> An expression that results in a character string value. If you use a constant, you must enclose it in quotation marks (" ").

> Example

> This procedure uses the ENCODE function to disguise a password that the user enters. The procedure then displays the encoded password.

> r-encode.p
>     DEFINE VARIABLE password AS CHARACTER FORMAT "x(16)".
>     DEFINE VARIABLE id AS CHARACTER FORMAT "x(12)".
>     DEFINE VARIABLE n-coded-p-wrd AS CHARACTER 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

> - You can use the ENCODE function to encode a string that contains double-byte characters.

> - The ENCODE function performs a one-way encoding operation that you cannot reverse. It is useful for storing scrambled copies of passwords in a database. It is impossible to determine the original password by examining the database. However, a procedure can prompt a user for 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 and any subsequent encoded comparisons must run in the same code page. In environments with multiple code pages, Progress strongly recommends that programs use the CODEPAGE-CONVERT function so that occurrences of the ENCODE function related to the same strings run in the same code page.

> - The output of the ENCODE function is 16 characters long. Make sure the target field size is at least 16 characters long.

Copyright © 2005 Progress Software Corporation www.progress.com Voice: (781) 280-4000 Fax: (781) 280-4095