xref: /PHP-5.5/ext/standard/tests/strings/crypt.phpt (revision 29a9ba96)
1--TEST--
2crypt() function
3--SKIPIF--
4<?php
5if (!function_exists('crypt')) {
6	die("SKIP crypt() is not available");
7}
8?>
9--FILE--
10<?php
11
12$str = 'rasmuslerdorf';
13$salt1 = 'rl';
14$res_1 = 'rl.3StKT.4T8M';
15$salt2 = '_J9..rasm';
16$res_2 = '_J9..rasmBYk8r9AiWNc';
17$salt3 = '$1$rasmusle$';
18$res_3 = '$1$rasmusle$rISCgZzpwk3UhDidwXvin0';
19$salt4 = '$2a$07$rasmuslerd............';
20$res_4 = '$2a$07$rasmuslerd............nIdrcHdxcUxWomQX9j6kvERCFjTg7Ra';
21
22echo (CRYPT_STD_DES)  ? ((crypt($str, $salt1) === $res_1) ? 'STD' : 'STD - ERROR') : 'STD', "\n";
23echo (CRYPT_EXT_DES)  ? ((crypt($str, $salt2) === $res_2) ? 'EXT' : 'EXT - ERROR') : 'EXT', "\n";
24echo (CRYPT_MD5)      ? ((crypt($str, $salt3) === $res_3) ? 'MD5' : 'MD5 - ERROR') : 'MD5', "\n";
25echo (CRYPT_BLOWFISH) ? ((crypt($str, $salt4) === $res_4) ? 'BLO' : 'BLO - ERROR') : 'BLO', "\n";
26
27var_dump(crypt($str));
28var_dump(crypt());
29var_dump(crypt("", "", ""));
30
31?>
32--EXPECTF--
33STD
34EXT
35MD5
36BLO
37string(%d) "%s"
38
39Warning: crypt() expects at least 1 parameter, 0 given in %s on line %d
40NULL
41
42Warning: crypt() expects at most 2 parameters, 3 given in %s on line %d
43NULL
44