xref: /PHP-7.3/ext/standard/tests/strings/crypt.phpt (revision 17ccbeec)
1--TEST--
2crypt() function
3--FILE--
4<?php
5
6$str = 'rasmuslerdorf';
7$salt1 = 'rl';
8$res_1 = 'rl.3StKT.4T8M';
9$salt2 = '_J9..rasm';
10$res_2 = '_J9..rasmBYk8r9AiWNc';
11$salt3 = '$1$rasmusle$';
12$res_3 = '$1$rasmusle$rISCgZzpwk3UhDidwXvin0';
13$salt4 = '$2a$07$rasmuslerd............';
14$res_4 = '$2a$07$rasmuslerd............nIdrcHdxcUxWomQX9j6kvERCFjTg7Ra';
15
16echo (CRYPT_STD_DES)  ? ((crypt($str, $salt1) === $res_1) ? 'STD' : 'STD - ERROR') : 'STD', "\n";
17echo (CRYPT_EXT_DES)  ? ((crypt($str, $salt2) === $res_2) ? 'EXT' : 'EXT - ERROR') : 'EXT', "\n";
18echo (CRYPT_MD5)      ? ((crypt($str, $salt3) === $res_3) ? 'MD5' : 'MD5 - ERROR') : 'MD5', "\n";
19echo (CRYPT_BLOWFISH) ? ((crypt($str, $salt4) === $res_4) ? 'BLO' : 'BLO - ERROR') : 'BLO', "\n";
20
21var_dump(crypt($str));
22var_dump(crypt());
23var_dump(crypt("", "", ""));
24
25?>
26--EXPECTF--
27STD
28EXT
29MD5
30BLO
31
32Notice: crypt(): No salt parameter was specified. You must use a randomly generated salt and a strong hash function to produce a secure hash. in %s on line %d
33string(%d) "%s"
34
35Warning: crypt() expects at least 1 parameter, 0 given in %s on line %d
36NULL
37
38Warning: crypt() expects at most 2 parameters, 3 given in %s on line %d
39NULL
40