crypt_sha256.phpt 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. --TEST--
  2. crypt() SHA-256
  3. --FILE--
  4. <?php
  5. $tests = array(
  6. 1 => array(
  7. '$5$saltstring',
  8. 'Hello world!',
  9. '$5$saltstring$5B8vYYiY.CVt1RlTTf8KbXBH3hsxY/GNooZaBBGWEc5'
  10. ),
  11. 2 => array(
  12. '$5$rounds=10000$saltstringsaltstring',
  13. 'Hello world!',
  14. '$5$rounds=10000$saltstringsaltst$3xv.VbSHBb41AL9AvLeujZkZRBAwqFMz2.opqey6IcA'
  15. ),
  16. 3 => array(
  17. '$5$rounds=10000$saltstringsaltstring',
  18. 'Hello world!',
  19. '$5$rounds=10000$saltstringsaltst$3xv.VbSHBb41AL9AvLeujZkZRBAwqFMz2.opqey6IcA'
  20. ),
  21. 4 => array(
  22. '$5$rounds=5000$toolongsaltstring',
  23. 'This is just a test',
  24. '$5$rounds=5000$toolongsaltstrin$Un/5jzAHMgOGZ5.mWJpuVolil07guHPvOW8mGRcvxa5'
  25. ),
  26. 5 => array(
  27. '$5$rounds=1400$anotherlongsaltstring',
  28. 'a very much longer text to encrypt. This one even stretches over morethan one line.',
  29. '$5$rounds=1400$anotherlongsalts$Rx.j8H.h8HjEDGomFU8bDkXm3XIUnzyxf12oP84Bnq1'
  30. ),
  31. 6 => array(
  32. '$5$rounds=77777$short',
  33. 'we have a short salt string but not a short password',
  34. '$5$rounds=77777$short$JiO1O3ZpDAxGJeaDIuqCoEFysAe1mZNJRs3pw0KQRd/'
  35. ),
  36. 7 => array(
  37. '$5$rounds=123456$asaltof16chars..',
  38. 'a short string',
  39. '$5$rounds=123456$asaltof16chars..$gP3VQ/6X7UUEW3HkBn2w1/Ptq2jxPyzV/cZKmF/wJvD'
  40. ),
  41. 8 => array(
  42. '$5$rounds=10$roundstoolow',
  43. 'the number of rounds is too low',
  44. '*0'
  45. ),
  46. 9 => array(
  47. '$5$rounds=1000000000$roundstoohigh',
  48. 'the number of rounds is too high',
  49. '*0'
  50. )
  51. );
  52. foreach ($tests as $iter => $t) {
  53. $res = crypt($t[1], $t[0]);
  54. if ($res != $t[2]) echo "Iteration $iter failed.
  55. Expected: <$t[2]>
  56. Got <$res>\n";
  57. }
  58. echo "Passes.";?>
  59. --EXPECT--
  60. Passes.