PageRenderTime 25ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 0ms

/source/function/function_seccode.php

https://github.com/kuaileshike/upload
PHP | 64 lines | 53 code | 5 blank | 6 comment | 14 complexity | e60654ab35808341507de5dc102332e2 MD5 | raw file
  1. <?php
  2. /**
  3. * [Discuz!] (C)2001-2099 Comsenz Inc.
  4. * This is NOT a freeware, use is subject to license terms
  5. *
  6. * $Id: function_seccode.php 26635 2011-12-19 01:59:13Z zhangguosheng $
  7. */
  8. if(!defined('IN_DISCUZ')) {
  9. exit('Access Denied');
  10. }
  11. function make_seccode($idhash){
  12. global $_G;
  13. $seccode = random(6, 1);
  14. $seccodeunits = '';
  15. if($_G['setting']['seccodedata']['type'] == 1) {
  16. $lang = lang('seccode');
  17. $len = strtoupper(CHARSET) == 'GBK' ? 2 : 3;
  18. $code = array(substr($seccode, 0, 3), substr($seccode, 3, 3));
  19. $seccode = '';
  20. for($i = 0; $i < 2; $i++) {
  21. $seccode .= substr($lang['chn'], $code[$i] * $len, $len);
  22. }
  23. } elseif($_G['setting']['seccodedata']['type'] == 3) {
  24. $s = sprintf('%04s', base_convert($seccode, 10, 20));
  25. $seccodeunits = 'CEFHKLMNOPQRSTUVWXYZ';
  26. } else {
  27. $s = sprintf('%04s', base_convert($seccode, 10, 24));
  28. $seccodeunits = 'BCEFGHJKMPQRTVWXY2346789';
  29. }
  30. if($seccodeunits) {
  31. $seccode = '';
  32. for($i = 0; $i < 4; $i++) {
  33. $unit = ord($s{$i});
  34. $seccode .= ($unit >= 0x30 && $unit <= 0x39) ? $seccodeunits[$unit - 0x30] : $seccodeunits[$unit - 0x57];
  35. }
  36. }
  37. dsetcookie('seccode'.$idhash, authcode(strtoupper($seccode)."\t".(TIMESTAMP - 180)."\t".$idhash."\t".FORMHASH, 'ENCODE', $_G['config']['security']['authkey']), 0, 1, true);
  38. return $seccode;
  39. }
  40. function make_secqaa($idhash) {
  41. global $_G;
  42. loadcache('secqaa');
  43. $secqaakey = max(1, random(1, 1));
  44. if($_G['cache']['secqaa'][$secqaakey]['type']) {
  45. if(file_exists($qaafile = libfile('secqaa/'.$_G['cache']['secqaa'][$secqaakey]['question'], 'class'))) {
  46. @include_once $qaafile;
  47. $class = 'secqaa_'.$_G['cache']['secqaa'][$secqaakey]['question'];
  48. if(class_exists($class)) {
  49. $qaa = new $class();
  50. if(method_exists($qaa, 'make')) {
  51. $_G['cache']['secqaa'][$secqaakey]['answer'] = md5($qaa->make($_G['cache']['secqaa'][$secqaakey]['question']));
  52. }
  53. }
  54. }
  55. }
  56. dsetcookie('secqaa'.$idhash, authcode($_G['cache']['secqaa'][$secqaakey]['answer']."\t".(TIMESTAMP - 180)."\t".$idhash."\t".FORMHASH, 'ENCODE', $_G['config']['security']['authkey']), 0, 1, true);
  57. return $_G['cache']['secqaa'][$secqaakey]['question'];
  58. }
  59. ?>