plugins/SpecialUserFuncs.php
changeset 401 6ae6e387a0e3
parent 387 92664d2efab8
child 402 d907601ccad2
equal deleted inserted replaced
400:7eef739a5b81 401:6ae6e387a0e3
  1317     echo $session->make_captcha();
  1317     echo $session->make_captcha();
  1318     return;
  1318     return;
  1319   }
  1319   }
  1320   
  1320   
  1321   $hash = $paths->getParam(0);
  1321   $hash = $paths->getParam(0);
  1322   if ( !$hash || !preg_match('#^([0-9a-f]*){32,32}$#i', $hash) )
  1322   if ( !$hash || !preg_match('#^([0-9a-f]*){32,40}$#i', $hash) )
  1323   {
  1323   {
  1324     $paths->main_page();
  1324     $paths->main_page();
  1325   }
  1325   }
  1326   
  1326   
  1327   // Determine code length
  1327   $code = $session->generate_captcha_code();
  1328   $ip = ip2hex($_SERVER['REMOTE_ADDR']);
  1328   $q = $db->sql_query('UPDATE ' . table_prefix . "captcha SET code = '$code' WHERE session_id = '$hash';");
  1329   if ( !$ip )
       
  1330     die('(very desperate) Hacking attempt');
       
  1331   $q = $db->sql_query('SELECT CHAR_LENGTH(salt) AS len FROM ' . table_prefix . 'session_keys WHERE session_key = \'' . $db->escape($hash) . '\' AND source_ip = \'' . $db->escape($ip) . '\';');
       
  1332   if ( !$q )
  1329   if ( !$q )
  1333     $db->_die('SpecialUserFuncs selecting CAPTCHA code');
  1330     $db->_die();
  1334   if ( $db->numrows() < 1 )
       
  1335     die('Invalid hash or hacking attempt by IP');
       
  1336   
       
  1337   // Generate code
       
  1338   $row = $db->fetchrow();
       
  1339   $db->free_result();
       
  1340   $len = intval($row['len']);
       
  1341   if ( $len < 4 )
       
  1342     $len = 7;
       
  1343   $code = $session->generate_captcha_code($len);
       
  1344   
       
  1345   // Update database with new code
       
  1346   $q = $db->sql_query('UPDATE ' . table_prefix . 'session_keys SET salt = \'' . $code . '\' WHERE session_key = \'' . $db->escape($hash) . '\' AND source_ip = \'' . $db->escape($ip) . '\';');
       
  1347   if ( !$q )
       
  1348     $db->_die('SpecialUserFuncs generating new CAPTCHA confirmation code');
       
  1349   
  1331   
  1350   require ( ENANO_ROOT.'/includes/captcha.php' );
  1332   require ( ENANO_ROOT.'/includes/captcha.php' );
  1351   $captcha = new captcha($code);
  1333   $captcha = captcha_object($hash, 'freecap');
       
  1334   $captcha->debug = true;
  1352   $captcha->make_image();
  1335   $captcha->make_image();
       
  1336   
  1353   exit;
  1337   exit;
  1354 }
  1338 }
  1355 
  1339 
  1356 function page_Special_PasswordReset()
  1340 function page_Special_PasswordReset()
  1357 {
  1341 {