crypt
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 an encrypted string based on the salt.
key | is the password or data to encrypt.
|
salt | is the salt used to
randomize the encryption. The non-DES salt format is $<ID>$<SALT>$.
|
There are several encryption methods available which are triggered by the
contents of the salt string.
Method |
Salt prefix |
Max salt length |
Max key length |
Max encoded length |
Returns |
DES | N/A | 2 | 8 | 13 | <salt><pwd> |
MD5 | $1$ | 6 | unlimited | 22 | $<1>$<salt>$<pwd> |
Blowfish | $2a$ | 16 | 72 | 53 | $<2a>$<salt>$<pwd> |
SHA-256 | $5$ | 16 | unlimited | 43 | $<5>$<salt>$<pwd> |
SHA-512 | $6$ | 16 | unlimited | 86 | $<6>$<salt>$<pwd> |
Notes
Only DES is supported on Windows, VMS, and MVS.
Example
Encrypt the password using a DES salt and store it 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");
Encrypt the password using a SHA-512 salt:
pwd = prompt("Please enter password ==> ");
pwd = crypt(pwd,"$6$BF6pxKiRWVZl$");
printf("SHA-512 value is "^^pwd)