crypt

DES password and data encryption.

Available in:

Apps (win) Apps (char) Reportwriter RPC Standalone PL
X X X X X

Syntax

string crypt(key,salt)
string       key
string       salt

Description

Crypt() returns a 13 character encrypted string. The first two characters are the salt that was used to do the encryption.
key is the password or data to encrypt.
salt is the two-character salt used to randomize the encryption.

Example

Encrypt the password stored in the database.
pwd = prompt("Please enter password ==> ");
pwd = crypt(pwd,"n9");
exec_sql("insert into users values(:1,:2)",:uid,:pwd);
Verify that the password is correct.
uid  = prompt("Please enter userid ==> ");
pwd  = prompt("Please enter password ==> ");
pwd2 = list_curr(list_open("select pwd from users where uid = &uid",1),0);
pwd  = crypt(pwd,substr(pwd2,1,2));
if (pwd == pwd2) printf("Passwords match");
else             printf("Passwords do not match");