PageRenderTime 50ms CodeModel.GetById 23ms RepoModel.GetById 0ms app.codeStats 0ms

/tools/captcha/captchac_lib.php

https://bitbucket.org/ElecTriNo/bbbweb
PHP | 61 lines | 30 code | 15 blank | 16 comment | 8 complexity | 5eea23fcc887e829ba91981e434567e3 MD5 | raw file
  1. <?php
  2. // -------------------------------------------------------------------------------------
  3. // Captcha Creator PHP Image Displaying Script.
  4. // Copyright (c) 2007 Alexandru Marias. All rights reserved
  5. // Web: http://www.captchacreator.com
  6. // Phone: +40722486348
  7. // ----------------------------------------------------------------
  8. session_start();
  9. function RandomCode($min,$max) // Chose the turing code
  10. {
  11. // Choosing a random Security Code
  12. Global $CSrc; // CSrc contains the characters from which the Captcha Code will be generated
  13. $srclen = strlen($CSrc)-1;
  14. // Chose the length of the turing code
  15. $length = mt_rand($min,$max); // Between 4 and 8 chars
  16. $Code = '';
  17. // Fill the turing string with characters and numbers from $src
  18. for($i=0; $i<$length; $i++)
  19. $Code .= substr($CSrc, mt_rand(0, $srclen), 1);
  20. return $Code;
  21. }
  22. // -------------------------------------------------------------------------------------
  23. function CheckCaptcha($Turing)
  24. {
  25. global $ImageCode;
  26. if ( session_id() == "" )
  27. {
  28. // We have no session id. There is no captcha code stored anywhere
  29. // Return false
  30. $ImageCode = 'wrong'; return 0;
  31. }
  32. if ( !isset( $_SESSION['turing_string'] ) )
  33. {
  34. // We have a session id, but the Turing String is empty, it was not generated yet.
  35. // Return true
  36. $ImageCode = ''; return 1;
  37. }
  38. else if ( strtoupper($_SESSION['turing_string']) == strtoupper($Turing) )
  39. {
  40. // Session id is ok, and Generated captcha is identical to user entered captcha
  41. // Return true
  42. $ImageCode = 'ok'; return 1;
  43. }
  44. else { $ImageCode = 'wrong'; return 0; }
  45. }
  46. ?>