xref: /PHP-8.0/ext/standard/tests/strings/crypt.phpt (revision 9975986b)
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
21try {
22    var_dump(crypt($str));
23} catch (ArgumentCountError $e) {
24    echo $e->getMessage(), "\n";
25}
26
27?>
28--EXPECT--
29STD
30EXT
31MD5
32BLO
33crypt() expects exactly 2 arguments, 1 given
34