function getHash($password, $salt = false) { if (is_integer($salt)) { $salt = getRandomString($salt); } return $salt === false ? md5($password) : md5($salt . $password) . ':' . $salt; }
function newUserId() { $name = getRandomString(); $sql = sprintf('INSERT INTO users SET name="%s", created=NOW(), modified=NOW()', r($name)); mysql_query($sql) or die(mysql_error()); $user_id = mysql_insert_id(); return $user_id; }
public function createTestUser() { $id = $this->insert(' insert into users (user_name, b_sex, email, passwd, dt_reg, msg) values (?, ?, ?, ?, UNIX_TIMESTAMP(), ?)', array('', rand(SEX_BOY, SEX_GIRL), '@mail.ru', md5('1'), getRandomString(100, true, 10))); $this->update('update users set user_name=?, email=? where id_user=?', array("user{$id}", "{$id}@mail.ru", $id)); return $id; }
function getRandomImageForPos($panelsDir, $pos) { $fullPosName = posAbbrToFull($pos); $filename = ""; $fileListDir = "filelists/"; if ($fullPosName != "") { $serializedPaths = file_get_contents($fileListDir . $fullPosName . "Paths.txt"); $allFiles = unserialize($serializedPaths); $filename = getRandomString($allFiles); } return $filename; }
static function user_login($IN, $db) { $db->query("SELECT password_hash, id FROM user WHERE BINARY name = ? AND deleted_at IS NULL", $IN['username']); if ($row = $db->fetch()) { if (password_verify($IN['password'], $row['password_hash'])) { $_SESSION['authorized'] = $row['id']; $session_token = getRandomString(16); $db->query("UPDATE user\n SET session_token=?\n WHERE id=?;", $session_token, $row['id']); $return = array("token" => $session_token, "id" => $row['id']); API::respond(true, $return); } } API::respond(false, "Username or password was incorrect"); }
public function show() { global $USER, $PLANET, $resource, $pricelist, $reslist, $LNG; $targetGalaxy = HTTP::_GP('galaxy', (int) $PLANET['galaxy']); $targetSystem = HTTP::_GP('system', (int) $PLANET['system']); $targetPlanet = HTTP::_GP('planet', (int) $PLANET['planet']); $targetType = HTTP::_GP('type', (int) $PLANET['planet_type']); $mission = HTTP::_GP('target_mission', 0); $Fleet = array(); $FleetRoom = 0; $allyInfo = $GLOBALS['DATABASE']->query("SELECT FleetCapa FROM `uni1_alliance` WHERE id = " . $USER['ally_id'] . ";"); $allyInfo = $GLOBALS['DATABASE']->fetch_array($allyInfo); $listorder = array(210, 212, 202, 203, 204, 205, 229, 209, 206, 207, 208, 217, 215, 213, 211, 220, 224, 219, 223, 225, 226, 214, 216, 230, 227, 228, 222, 218, 221); foreach ($listorder as $id => $ShipID) { $amount = max(0, round(HTTP::_GP('ship' . $ShipID, 0.0, 0.0))); if ($amount < 1 || $ShipID == 212) { continue; } $Fleet[$ShipID] = $amount; $FleetRoom += $pricelist[$ShipID]['capacity'] * $amount; $FleetRoom += $FleetRoom / 100 * getbonusOneBis(1207, $USER['academy_1207']) + $FleetRoom / 100 * $allyInfo['FleetCapa']; } foreach ($Fleet as $Ship => $Count) { if ($Count > $PLANET[$resource[$Ship]]) { $this->printMessage($LNG['fl_not_all_ship_avalible']); } } $FleetRoom *= 1 + $USER['factor']['ShipStorage']; if (empty($Fleet)) { FleetFunctions::GotoFleetPage(); } $FleetData = array('fleetroom' => floattostring($FleetRoom), 'gamespeed' => FleetFunctions::GetGameSpeedFactor(), 'fleetspeedfactor' => max(0, 1 + $USER['factor']['FlyTime']), 'planet' => array('galaxy' => $PLANET['galaxy'], 'system' => $PLANET['system'], 'planet' => $PLANET['planet'], 'planet_type' => $PLANET['planet_type']), 'maxspeed' => FleetFunctions::GetFleetMaxSpeed($Fleet, $USER), 'ships' => FleetFunctions::GetFleetShipInfo($Fleet, $USER), 'fleetMinDuration' => MIN_FLEET_TIME); $token = getRandomString(); $_SESSION['fleet'][$token] = array('time' => TIMESTAMP, 'fleet' => $Fleet, 'fleetRoom' => $FleetRoom); $shortcutList = $this->GetUserShotcut(); $colonyList = $this->GetColonyList(); $ACSList = $this->GetAvalibleACS(); if (!empty($shortcutList)) { $shortcutAmount = max(array_keys($shortcutList)); } else { $shortcutAmount = 0; } $this->tplObj->loadscript('flotten.js'); $this->tplObj->execscript('updateVars();FleetTime();window.setInterval("FleetTime()", 1000);'); $this->tplObj->assign_vars(array('token' => $token, 'mission' => $mission, 'shortcutList' => $shortcutList, 'shortcutMax' => $shortcutAmount, 'colonyList' => $colonyList, 'ACSList' => $ACSList, 'galaxy' => $targetGalaxy, 'system' => $targetSystem, 'planet' => $targetPlanet, 'type' => $targetType, 'speedSelect' => FleetFunctions::$allowedSpeed, 'typeSelect' => array(1 => $LNG['type_planet'][1], 2 => $LNG['type_planet'][2], 3 => $LNG['type_planet'][3], 4 => $LNG['type_planet'][4]), 'fleetdata' => $FleetData)); $this->display('page.fleetStep1.default.tpl'); }
function generateRandomString($length = 32) { try { $string = random_bytes($length); $randomString = bin2hex($string); } catch (TypeError $e) { // Well, it's an integer, so this IS unexpected. //die("An unexpected error has occurred"); $randomString = getRandomString($length); } catch (Error $e) { // This is also unexpected because 32 is a reasonable integer. //die("An unexpected error has occurred"); $randomString = getRandomString($length); } catch (Exception $e) { // If you get this message, the CSPRNG failed hard. //die("Could not generate a random string. Is our OS secure?"); $randomString = getRandomString($length); } return substr($randomString, 0, $length); }
function verifyImage($type = 1, $length = 4, $pixel = 30, $line = 0, $sess_name = "verify") { session_start(); Header("Content-type: image/PNG"); //Header("Content-type: image/GIF"); //创建画布 $width = 80; $height = 30; $image = imagecreatetruecolor($width, $height); $white = imagecolorallocate($image, 255, 255, 255); $black = imagecolorallocate($image, 0, 0, 0); imagefilledrectangle($image, 1, 1, $width - 2, $height - 2, $white); $chars = getRandomString($type, $length); $_SESSION[$sess_name] = $chars; $fontfiles = array("msyh.ttc", "msyhl.ttc", "msyhbd.ttc"); for ($i = 0; $i < $length; $i++) { $size = mt_rand(14, 18); $angle = mt_rand(-15, 15); $x = 5 + $i * $size; //echo $x; $y = mt_rand(20, 26); $fontfile = "../fonts/" . $fontfiles[mt_rand(0, count($fontfiles) - 1)]; $color = imagecolorallocate($image, mt_rand(50, 90), mt_rand(80, 200), mt_rand(90, 180)); $text = substr($chars, $i, 1); imagettftext($image, $size, $angle, $x, $y, $color, $fontfile, $text); } if ($pixel) { for ($i = 0; $i < 50; $i++) { imagesetpixel($image, mt_rand(0, $width - 1), mt_rand(0, $height - 1), $black); } } if ($line) { for ($i = 1; $i < $line; $i++) { $color = imagecolorallocate($image, mt_rand(50, 90), mt_rand(80, 200), mt_rand(90, 180)); imageline($image, mt_rand(0, $width - 1), mt_rand(0, $height - 1), mt_rand(0, $width - 1), mt_rand(0, $height - 1), $color); } } //echo $chars; ImagePNG($image); //ImageGIF($image); ImageDestroy($image); }
function SetTrackingCookie($len = 32) { $MAX_ITER = 5; $iter = 0; $conn = mysqlConnectDB("webtracking"); //connect to database webtracking while ($iter < $MAX_ITER) { $token = getRandomString($len); if (saveTokenInDB($conn, $token)) { //expires in 30 minutes. The length of random string is 32. // Need to set domain = NULL as chrome prevents creration of cookie for localhost. setcookie("token", $token, time() + 30 * 60, "/webtracking", NULL, false, true); break; } $iter++; } if ($iter == $MAX_ITER) { die("Some Error occured try again!"); } }
public function show() { global $USER, $PLANET, $pricelist, $reslist, $LNG; $targetGalaxy = HTTP::_GP('galaxy', (int) $PLANET['galaxy']); $targetSystem = HTTP::_GP('system', (int) $PLANET['system']); $targetPlanet = HTTP::_GP('planet', (int) $PLANET['planet']); $targetType = HTTP::_GP('type', (int) $PLANET['planet_type']); $mission = HTTP::_GP('target_mission', 0); $Fleet = array(); $FleetRoom = 0; foreach ($reslist['fleet'] as $id => $ShipID) { $amount = max(0, round(HTTP::_GP('ship' . $ShipID, 0.0, 0.0))); if ($amount < 1 || $ShipID == 212) { continue; } $Fleet[$ShipID] = $amount; $FleetRoom += $pricelist[$ShipID]['capacity'] * $amount; } $FleetRoom *= 1 + $USER['factor']['ShipStorage']; if (empty($Fleet)) { FleetFunctions::GotoFleetPage(); } $FleetData = array('fleetroom' => floatToString($FleetRoom), 'gamespeed' => FleetFunctions::GetGameSpeedFactor(), 'fleetspeedfactor' => max(0, 1 + $USER['factor']['FlyTime']), 'planet' => array('galaxy' => $PLANET['galaxy'], 'system' => $PLANET['system'], 'planet' => $PLANET['planet'], 'planet_type' => $PLANET['planet_type']), 'maxspeed' => FleetFunctions::GetFleetMaxSpeed($Fleet, $USER), 'ships' => FleetFunctions::GetFleetShipInfo($Fleet, $USER), 'fleetMinDuration' => MIN_FLEET_TIME); $token = getRandomString(); $_SESSION['fleet'][$token] = array('time' => TIMESTAMP, 'fleet' => $Fleet, 'fleetRoom' => $FleetRoom); $shortcutList = $this->GetUserShotcut(); $colonyList = $this->GetColonyList(); $ACSList = $this->GetAvalibleACS(); if (!empty($shortcutList)) { $shortcutAmount = max(array_keys($shortcutList)); } else { $shortcutAmount = 0; } $this->tplObj->loadscript('flotten.js'); $this->tplObj->execscript('updateVars();FleetTime();window.setInterval("FleetTime()", 1000);'); $this->assign(array('token' => $token, 'mission' => $mission, 'shortcutList' => $shortcutList, 'shortcutMax' => $shortcutAmount, 'colonyList' => $colonyList, 'ACSList' => $ACSList, 'galaxy' => $targetGalaxy, 'system' => $targetSystem, 'planet' => $targetPlanet, 'type' => $targetType, 'speedSelect' => FleetFunctions::$allowedSpeed, 'typeSelect' => array(1 => $LNG['type_planet'][1], 2 => $LNG['type_planet'][2], 3 => $LNG['type_planet'][3]), 'fleetdata' => $FleetData)); $this->display('page.fleetStep1.default.tpl'); }
<?php /** * 2Moons * Copyright (C) 2012 Jan Kröpke * * For the full copyright and license information, please view the LICENSE * * @package 2Moons * @author Jan Kröpke <*****@*****.**> * @copyright 2012 Jan Kröpke <*****@*****.**> * @licence MIT * @version 1.7.2 (2013-03-18) * @info $Id$ * @link http://2moons.cc/ */ $token = getRandomString(); $db = Database::get(); $fleetResult = $db->update("UPDATE %%FLEETS_EVENT%% SET `lock` = :token WHERE `lock` IS NULL AND `time` <= :time;", array(':time' => TIMESTAMP, ':token' => $token)); if ($db->rowCount() !== 0) { require 'includes/classes/class.FlyingFleetHandler.php'; $fleetObj = new FlyingFleetHandler(); $fleetObj->setToken($token); $fleetObj->run(); $db->update("UPDATE %%FLEETS_EVENT%% SET `lock` = NULL WHERE `lock` = :token;", array(':token' => $token)); }
$seprator = "|"; $message = "User Added"; $uname = mysql_real_escape_string($_POST['uname']); $password = mysql_real_escape_string($_POST['upassword']); $mdpass = md5($password); $fname = mysql_real_escape_string($_POST['fname']); $lname = mysql_real_escape_string($_POST['lname']); $designation = mysql_real_escape_string($_POST['designation']); $organisation = mysql_real_escape_string($_POST['organisation']); $uemail = mysql_real_escape_string($_POST['uemail']); $user_ip = $_SERVER['REMOTE_ADDR']; function getRandomString($length) { $validCharacters = "1080nordiff00123456vikas09084abcdefghijklmnopqrstuvwxyz"; $validCharNumber = strlen($validCharacters); $result = ""; for ($i = 0; $i < $length; $i++) { $index = mt_rand(0, $validCharNumber - 1); $result .= $validCharacters[$index]; } return $result; } $activation_code = getRandomString(50); $finalreg = $registration->UserRegister($uname, $mdpass, $fname, $lname, $designation, $organisation, $uemail, $user_ip, $activation_code); } ?> </div> </div> </section> <?php require $get_footer;
public function insertDeclaration() { $curDate = getCurDateStamp(); $d_code = getRandomString(10); $data = array('d_code' => $d_code, 'd_msg' => stripslashes($this->input->post('declaration_msg')), 'd_status' => $this->input->post('declaration_status'), 'created_at' => $curDate); $data['d_status'] = is_null($data['d_status']) ? 0 : 1; if (!is_null($data['d_msg']) && $data['d_msg'] !== "") { //Transfering data to Model $this->declaration_model->insert_declaration($data); $data['d_successful'] = 'Data Inserted Successfully'; } //Loading View $this->dailyDeclarations(); }
function install($adminPassword, $email, $timezoneOffset) { global $Language; $stdOut = array(); $timezone = timezone_name_from_abbr("", $timezoneOffset, 0); date_default_timezone_set($timezone); $currentDate = Date::current(DB_DATE_FORMAT); // ============================================================================ // Create directories // ============================================================================ // 7=read,write,execute | 5=read,execute $dirpermissions = 0755; $firstPostSlug = 'first-post'; if (!mkdir(PATH_POSTS . $firstPostSlug, $dirpermissions, true)) { $errorText = 'Error when trying to created the directory=>' . PATH_POSTS . $firstPostSlug; error_log($errorText, 0); } if (!mkdir(PATH_PAGES . 'error', $dirpermissions, true)) { $errorText = 'Error when trying to created the directory=>' . PATH_PAGES . 'error'; error_log($errorText, 0); } if (!mkdir(PATH_PLUGINS_DATABASES . 'pages', $dirpermissions, true)) { $errorText = 'Error when trying to created the directory=>' . PATH_PLUGINS_DATABASES . 'pages'; error_log($errorText, 0); } if (!mkdir(PATH_PLUGINS_DATABASES . 'simplemde', $dirpermissions, true)) { $errorText = 'Error when trying to created the directory=>' . PATH_PLUGINS_DATABASES . 'simplemde'; error_log($errorText, 0); } if (!mkdir(PATH_PLUGINS_DATABASES . 'tags', $dirpermissions, true)) { $errorText = 'Error when trying to created the directory=>' . PATH_PLUGINS_DATABASES . 'tags'; error_log($errorText, 0); } if (!mkdir(PATH_UPLOADS, $dirpermissions, true)) { $errorText = 'Error when trying to created the directory=>' . PATH_UPLOADS; error_log($errorText, 0); } // ============================================================================ // Create files // ============================================================================ $dataHead = "<?php defined('BLUDIT') or die('Bludit CMS.'); ?>" . PHP_EOL; // File pages.php $data = array('error' => array('description' => 'Error page', 'username' => 'admin', 'tags' => array(), 'status' => 'published', 'date' => $currentDate, 'position' => 0)); file_put_contents(PATH_DATABASES . 'pages.php', $dataHead . json_encode($data, JSON_PRETTY_PRINT), LOCK_EX); // File posts.php $data = array($firstPostSlug => array('description' => 'Welcome to Bludit', 'username' => 'admin', 'status' => 'published', 'tags' => array('bludit' => 'Bludit', 'cms' => 'CMS', 'flat-files' => 'Flat files'), 'allowComments' => 'false', 'date' => $currentDate)); file_put_contents(PATH_DATABASES . 'posts.php', $dataHead . json_encode($data, JSON_PRETTY_PRINT), LOCK_EX); // File site.php $data = array('title' => 'Bludit', 'slogan' => 'cms', 'description' => '', 'footer' => Date::current('Y'), 'language' => $Language->getCurrentLocale(), 'locale' => $Language->getCurrentLocale(), 'timezone' => $timezone, 'theme' => 'pure', 'adminTheme' => 'default', 'homepage' => '', 'postsperpage' => '6', 'uriPost' => '/post/', 'uriPage' => '/', 'uriTag' => '/tag/', 'url' => 'http://' . DOMAIN . HTML_PATH_ROOT, 'cliMode' => 'true', 'emailFrom' => 'no-reply@' . DOMAIN); file_put_contents(PATH_DATABASES . 'site.php', $dataHead . json_encode($data, JSON_PRETTY_PRINT), LOCK_EX); $salt = getRandomString(); $passwordHash = sha1($adminPassword . $salt); // File users.php $data = array('admin' => array('firstName' => '', 'lastName' => '', 'twitter' => '', 'role' => 'admin', 'password' => $passwordHash, 'salt' => $salt, 'email' => $email, 'registered' => $currentDate)); file_put_contents(PATH_DATABASES . 'users.php', $dataHead . json_encode($data, JSON_PRETTY_PRINT), LOCK_EX); // File security.php $data = array('minutesBlocked' => 5, 'numberFailuresAllowed' => 10, 'blackList' => array()); file_put_contents(PATH_DATABASES . 'security.php', $dataHead . json_encode($data, JSON_PRETTY_PRINT), LOCK_EX); // File tags.php file_put_contents(PATH_DATABASES . 'tags.php', $dataHead . json_encode(array('postsIndex' => array('bludit' => array('name' => 'Bludit', 'posts' => array('first-post')), 'cms' => array('name' => 'CMS', 'posts' => array('first-post')), 'flat-files' => array('name' => 'Flat files', 'posts' => array('first-post'))), 'pagesIndex' => array()), JSON_PRETTY_PRINT), LOCK_EX); // PLUGINS // File plugins/pages/db.php file_put_contents(PATH_PLUGINS_DATABASES . 'pages' . DS . 'db.php', $dataHead . json_encode(array('position' => 0, 'homeLink' => true, 'label' => $Language->get('Pages')), JSON_PRETTY_PRINT), LOCK_EX); // File plugins/simplemde/db.php file_put_contents(PATH_PLUGINS_DATABASES . 'simplemde' . DS . 'db.php', $dataHead . json_encode(array('position' => 0, 'tabSize' => 4, 'toolbar' => '"bold", "italic", "heading", "|", "quote", "unordered-list", "|", "link", "image", "code", "horizontal-rule", "|", "preview", "side-by-side", "fullscreen", "guide"'), JSON_PRETTY_PRINT), LOCK_EX); // File plugins/tags/db.php file_put_contents(PATH_PLUGINS_DATABASES . 'tags' . DS . 'db.php', $dataHead . json_encode(array('position' => 0, 'label' => $Language->get('Tags')), JSON_PRETTY_PRINT), LOCK_EX); // File index.txt for error page $data = 'Title: ' . $Language->get('Error') . ' Content: ' . $Language->get('The page has not been found'); file_put_contents(PATH_PAGES . 'error' . DS . 'index.txt', $data, LOCK_EX); // File index.txt for welcome post $data = 'Title: ' . $Language->get('First post') . ' Content: ## ' . $Language->get('Congratulations you have successfully installed your Bludit') . ' ### ' . $Language->get('Whats next') . ' - ' . $Language->get('Manage your Bludit from the admin panel') . ' - ' . $Language->get('Follow Bludit on') . ' [Twitter](https://twitter.com/bludit) / [Facebook](https://www.facebook.com/pages/Bludit/239255789455913) / [Google+](https://plus.google.com/+Bluditcms) - ' . $Language->get('Visit the support forum') . ' - ' . $Language->get('Read the documentation for more information') . ' - ' . $Language->get('Share with your friends and enjoy'); file_put_contents(PATH_POSTS . $firstPostSlug . DS . 'index.txt', $data, LOCK_EX); return true; }
function sendExpo() { global $LNG, $ProdGrid, $resource, $reslist, $CONF, $pricelist, $USER, $PLANET; $Type_search = HTTP::_GP('type_fouille', ''); $Popu = array(); $endtime = 0; if ($Type_search == 1) { $endtime = rand(7200, 9000); } elseif ($Type_search == 2) { $endtime = rand(14400, 16200); } elseif ($Type_search == 3) { $endtime = rand(21600, 23400); } foreach ($reslist['population'] as $id => $popID) { $amount = max(0, round(HTTP::_GP('population' . $popID, 0.0, 0.0))); if ($amount < 1) { continue; } $Popu[$popID] = $amount; } //if (empty($Popu)) //FleetFunctions::GotoFleetPage(); $token = getRandomString(); $_SESSION['population'][$token] = array('time' => TIMESTAMP, 'population' => $Popu); $fleetArray = $_SESSION['population'][$token]['population']; foreach ($fleetArray as $Ship => $Count) { if ($Count > $PLANET[$resource[$Ship]]) { $this->printMessage('<span class="rouge">' . $LNG['ls_explora_27'] . '</span>'); } } foreach ($fleetArray as $ShipID => $ShipCount) { $fleetData[] = $ShipID . ',' . floattostring($ShipCount); $planetQuery[] = $resource[$ShipID] . " = " . $resource[$ShipID] . " - " . floattostring($ShipCount); $PLANET[$resource[$ShipID]] -= floattostring($ShipCount); } $SQL = "LOCK TABLE uni1_explorations WRITE, " . USERS . " WRITE, " . PLANETS . " WRITE;\n\t\t\t\t UPDATE " . PLANETS . " SET " . implode(", ", $planetQuery) . " WHERE id = " . $PLANET['id'] . ";\n\t\t\t\t UPDATE " . USERS . " SET max_explore = max_explore + 1 WHERE id = " . $USER['id'] . ";\n\t\t\t\t INSERT INTO uni1_explorations SET\n\t\t\t\t userID = " . $USER['id'] . ",\n\t\t\t\t state = '1',\n\t\t\t\t type_of_search = " . $Type_search . ",\n\t\t\t\t start_planet_name = '" . $PLANET['name'] . "',\n\t\t\t\t start_system = " . $PLANET['system'] . ",\n\t\t\t\t start_planet = " . $PLANET['planet'] . ",\n\t\t\t\t end_planet_name = '" . $PLANET['name'] . "',\n\t\t\t\t start_time = " . TIMESTAMP . ",\n\t\t\t\t emd_time = " . (TIMESTAMP + $endtime) . ",\n\t\t\t\t population_array = '" . implode(';', $fleetData) . "',\n\t\t\t\t ships_array = '" . implode(';', $fleetData) . "';\n\t\t\t\t SET @explorationID = LAST_INSERT_ID();\n\t\t\t\t UNLOCK TABLES;"; $GLOBALS['DATABASE']->multi_query($SQL); $this->printMessage('<span class="vert">' . $LNG['ls_explora_26'] . '</span>', true, array('game.php?page=Explorations', 3)); $this->tplObj->assign_vars(array()); $this->display('page.explorations.busy.tpl'); }
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ $create_default = false; // When this is set to true, the export creates a default.txt file which can get converted to test.ans by calling create_default.php function getRandomString($length = 10) { $validCharacters = "abcdefghijklmnopqrstuxyvwzABCDEFGHIJKLMNOPQRSTUXYVWZ0123456789"; $validCharNumber = strlen($validCharacters); $result = ""; for ($i = 0; $i < $length; $i++) { $index = mt_rand(0, $validCharNumber - 1); $result .= $validCharacters[$index]; } return $result; } if (!is_dir("download")) { mkdir("download"); } $string = $_POST['value']; $filename = getRandomString(8); if ($create_default) { $f = fopen("default.txt", "w"); fwrite($f, $string); fclose($f); exit; } $f = fopen("download/" . $filename . ".ans", "w"); include "subs.php"; echo json_encode(array("filename" => $filename . ".ans"));
//执行查询 $MaxQuery = $pdo->query($SelectMax); //返回结果 $MaxRow = $MaxQuery->fetch(); print "Total data is {$MaxRow['0']}. \n"; //删除short字段 $count = $pdo->exec("ALTER TABLE `{$table}` DROP COLUMN short"); print "Deleted {$count} rows.\n"; //再添加short字段 $count = $pdo->exec("ALTER TABLE `{$table}` ADD COLUMN `short` varchar(32) NULL AFTER `keywords`, ADD UNIQUE INDEX `short` (`short`) ;"); print "ADD COLUMN {$count} OK!!!.\n"; //写入short code for ($i = 1; $i <= $MaxRow[0]; $i++) { //$MaxRow[0] a: $short_code = getRandomString(6); if ($up = $pdo->exec("UPDATE `{$table}` SET `short`='{$short_code}' WHERE (`id`='{$i}')")) { print "UPDATE DATE ID {$i} is OK..\n"; } elseif (strpos($pdo->errorInfo()[2], "short")) { //如果有碰撞,则跳转到a位置,重新生成,并且写入。 // $short_code = getRandomString(6); goto a; } else { echo $pdo->errorInfo()[2]; break; } } // $pdo->exec("INSERT INTO `$dbname`.`$table` (`id`, `keywords`) VALUES ('', '$keyword');"); //生成随机字符串方法 function getRandomString($len, $chars = null) {
<input type="text" name="email" /> <input type="submit" value="Reset My Password" /> </form>'; exit; } $email = $_GET['email']; include "settings.php"; connect(); $q = "select email from users where email='" . $email . "'"; $r = mysql_query($q); $n = mysql_num_rows($r); if ($n == 0) { echo "Email id is not registered"; die; } $token = getRandomString(10); $q = "insert into tokens (token,email) values ('" . $token . "','" . $email . "')"; mysql_query($q); function getRandomString($length) { $validCharacters = "ABCDEFGHIJKLMNPQRSTUXYVWZ123456789"; $validCharNumber = strlen($validCharacters); $result = ""; for ($i = 0; $i < $length; $i++) { $index = mt_rand(0, $validCharNumber - 1); $result .= $validCharacters[$index]; } return $result; } function mailresetlink($to, $token) {
function install($adminPassword, $email, $timezoneOffset) { global $Language; $stdOut = array(); $timezone = timezone_name_from_abbr('', $timezoneOffset, 0); if ($timezone === false) { $timezone = timezone_name_from_abbr('', $timezoneOffset, 0); } // Workaround bug #44780 date_default_timezone_set($timezone); $currentDate = Date::current(DB_DATE_FORMAT); // ============================================================================ // Create directories // ============================================================================ // 7=read,write,execute | 5=read,execute $dirpermissions = 0755; $firstPostSlug = 'first-post'; if (!mkdir(PATH_POSTS . $firstPostSlug, $dirpermissions, true)) { $errorText = 'Error when trying to created the directory=>' . PATH_POSTS . $firstPostSlug; error_log($errorText, 0); } if (!mkdir(PATH_PAGES . 'error', $dirpermissions, true)) { $errorText = 'Error when trying to created the directory=>' . PATH_PAGES . 'error'; error_log($errorText, 0); } if (!mkdir(PATH_PAGES . 'about', $dirpermissions, true)) { $errorText = 'Error when trying to created the directory=>' . PATH_PAGES . 'about'; error_log($errorText, 0); } if (!mkdir(PATH_PLUGINS_DATABASES . 'pages', $dirpermissions, true)) { $errorText = 'Error when trying to created the directory=>' . PATH_PLUGINS_DATABASES . 'pages'; error_log($errorText, 0); } if (!mkdir(PATH_PLUGINS_DATABASES . 'tinymce', $dirpermissions, true)) { $errorText = 'Error when trying to created the directory=>' . PATH_PLUGINS_DATABASES . 'tinymce'; error_log($errorText, 0); } if (!mkdir(PATH_PLUGINS_DATABASES . 'tags', $dirpermissions, true)) { $errorText = 'Error when trying to created the directory=>' . PATH_PLUGINS_DATABASES . 'tags'; error_log($errorText, 0); } if (!mkdir(PATH_PLUGINS_DATABASES . 'about', $dirpermissions, true)) { $errorText = 'Error when trying to created the directory=>' . PATH_PLUGINS_DATABASES . 'about'; error_log($errorText, 0); } if (!mkdir(PATH_UPLOADS_PROFILES, $dirpermissions, true)) { $errorText = 'Error when trying to created the directory=>' . PATH_UPLOADS_PROFILES; error_log($errorText, 0); } // ============================================================================ // Create files // ============================================================================ $dataHead = "<?php defined('BLUDIT') or die('Bludit CMS.'); ?>" . PHP_EOL; // File pages.php $data = array('error' => array('description' => 'Error page', 'username' => 'admin', 'tags' => array(), 'status' => 'published', 'date' => $currentDate, 'position' => 0), 'about' => array('description' => $Language->get('About your site or yourself'), 'username' => 'admin', 'tags' => array(), 'status' => 'published', 'date' => $currentDate, 'position' => 1)); file_put_contents(PATH_DATABASES . 'pages.php', $dataHead . json_encode($data, JSON_PRETTY_PRINT), LOCK_EX); // File posts.php $data = array($firstPostSlug => array('description' => $Language->get('Welcome to Bludit'), 'username' => 'admin', 'status' => 'published', 'tags' => array('bludit' => 'Bludit', 'cms' => 'CMS', 'flat-files' => 'Flat files'), 'allowComments' => 'false', 'date' => $currentDate)); file_put_contents(PATH_DATABASES . 'posts.php', $dataHead . json_encode($data, JSON_PRETTY_PRINT), LOCK_EX); // File site.php $data = array('title' => 'BLUDIT', 'slogan' => 'CMS', 'description' => '', 'footer' => 'Copyright © ' . Date::current('Y'), 'language' => $Language->getCurrentLocale(), 'locale' => $Language->getCurrentLocale(), 'timezone' => $timezone, 'theme' => 'pure', 'adminTheme' => 'default', 'homepage' => '', 'postsperpage' => '6', 'uriPost' => '/post/', 'uriPage' => '/', 'uriTag' => '/tag/', 'url' => 'http://' . DOMAIN . HTML_PATH_ROOT, 'cliMode' => 'true', 'emailFrom' => 'no-reply@' . DOMAIN); file_put_contents(PATH_DATABASES . 'site.php', $dataHead . json_encode($data, JSON_PRETTY_PRINT), LOCK_EX); // File users.php $salt = getRandomString(); $passwordHash = sha1($adminPassword . $salt); $data = array('admin' => array('firstName' => $Language->get('Administrator'), 'lastName' => '', 'twitter' => '', 'role' => 'admin', 'password' => $passwordHash, 'salt' => $salt, 'email' => $email, 'registered' => $currentDate)); file_put_contents(PATH_DATABASES . 'users.php', $dataHead . json_encode($data, JSON_PRETTY_PRINT), LOCK_EX); // File security.php $randomKey = getRandomString(); $randomKey = sha1($randomKey); $data = array('key1' => $randomKey, 'minutesBlocked' => 5, 'numberFailuresAllowed' => 10, 'blackList' => array()); file_put_contents(PATH_DATABASES . 'security.php', $dataHead . json_encode($data, JSON_PRETTY_PRINT), LOCK_EX); // File tags.php file_put_contents(PATH_DATABASES . 'tags.php', $dataHead . json_encode(array('postsIndex' => array('bludit' => array('name' => 'Bludit', 'posts' => array('first-post')), 'cms' => array('name' => 'CMS', 'posts' => array('first-post')), 'flat-files' => array('name' => 'Flat files', 'posts' => array('first-post'))), 'pagesIndex' => array()), JSON_PRETTY_PRINT), LOCK_EX); // PLUGINS // File plugins/pages/db.php file_put_contents(PATH_PLUGINS_DATABASES . 'pages' . DS . 'db.php', $dataHead . json_encode(array('position' => 0, 'homeLink' => true, 'label' => $Language->get('Pages')), JSON_PRETTY_PRINT), LOCK_EX); // File plugins/about/db.php file_put_contents(PATH_PLUGINS_DATABASES . 'about' . DS . 'db.php', $dataHead . json_encode(array('position' => 0, 'label' => $Language->get('About'), 'text' => $Language->get('this-is-a-brief-description-of-yourself-our-your-site')), JSON_PRETTY_PRINT), LOCK_EX); // File plugins/tinymce/db.php file_put_contents(PATH_PLUGINS_DATABASES . 'tinymce' . DS . 'db.php', $dataHead . json_encode(array('position' => 0, 'plugins' => 'autoresize, fullscreen, pagebreak, link, textcolor, code', 'toolbar' => 'bold italic underline strikethrough | alignleft aligncenter alignright | bullist numlist | styleselect | link forecolor backcolor removeformat | pagebreak code fullscreen'), JSON_PRETTY_PRINT), LOCK_EX); // File plugins/tags/db.php file_put_contents(PATH_PLUGINS_DATABASES . 'tags' . DS . 'db.php', $dataHead . json_encode(array('position' => 0, 'label' => $Language->get('Tags')), JSON_PRETTY_PRINT), LOCK_EX); // File index.txt for error page $data = 'Title: ' . $Language->get('Error') . ' Content: ' . $Language->get('The page has not been found'); file_put_contents(PATH_PAGES . 'error' . DS . 'index.txt', $data, LOCK_EX); // File index.txt for about page $data = 'Title: ' . $Language->get('About') . ' Content: ' . $Language->get('the-about-page-is-very-important') . ' ' . $Language->get('change-this-pages-content-on-the-admin-panel'); file_put_contents(PATH_PAGES . 'about' . DS . 'index.txt', $data, LOCK_EX); // File index.txt for welcome post $data = 'Title: ' . $Language->get('First post') . ' Content: ## ' . $Language->get('Whats next') . ' - ' . $Language->get('Manage your Bludit from the admin panel') . ' - ' . $Language->get('Follow Bludit on') . ' [Twitter](https://twitter.com/bludit) / [Facebook](https://www.facebook.com/bluditcms) / [Google+](https://plus.google.com/+Bluditcms) - ' . $Language->get('Chat with developers and users on Gitter') . ' - ' . $Language->get('Visit the support forum') . ' - ' . $Language->get('Read the documentation for more information') . ' - ' . $Language->get('Share with your friends and enjoy'); file_put_contents(PATH_POSTS . $firstPostSlug . DS . 'index.txt', $data, LOCK_EX); return true; }
public function addFileImg(DirItem $img) { AuthManager::checkAdminAccess(); //todo - НЕБЕЗОПАСНО! Разобраться с преобразованием картинок. Они портятся при перегонке формата $img->copyTo($this->DM->absFilePath(null, $img->getNameNoExt() . '_' . getRandomString(3), array_get_value(1, explode('/', $img->getMime())))); //SimpleImage::inst()->load($img)->save($this->DM->getDirItem(null, $img->getNameNoExt()), 'png')->close(); }
} $transaction = $db->get_row("select * from tbl_transaction where voucher_id={$voucher_id}"); function getRandomString() { $length = 7; $characters = '0123456789abcdefghijklmnopqrstuvwxyz'; // leng=35 $string = ''; for ($p = 0; $p < $length; $p++) { $string .= $characters[mt_rand(0, 35)]; } //35 in leng return $string; } //////////////////// $reserve = strtoupper(getRandomString()); $availability = $book->availability; $mobile = $_POST['mobile'] = '09358622156'; $address = $_POST['address'] = "ladan12"; $email = $_POST['email'] = "galiver_h"; $description = $_POST['description'] = "des"; $regdate = pdate("Y-m-d"); $currency = $transaction->currency; $rooms = $_POST['number_rooms']; /////////// check for inspect if (isset($_POST['total_amount'])) { $amount = $_POST['total_amount']; $db->query("update tbl_transaction set amount={$amount} where voucher_id={$voucher_id} and type=8"); } else { $amount = $transaction->amount; }
/** Get configuration from file. This function also offers the default * values for configuration values * * @param string $name * Name of configuration to fetch * * @return bool */ public function get($name) { // try to get value if (isset($this->content[$name])) { return $this->content[$name]; } // get possible root dir $root = dirname($_SERVER['SCRIPT_FILENAME']); $root = substr($root, 0, strlen($root) - strlen('admin/')); // get defaults switch ($name) { case 'version': return $this->current_version; case 'domain': return $_SERVER['SERVER_NAME']; case 'dir_admin': return $root . '/admin'; case 'dir_data': return $root . '/data'; case 'dir_runtime': return $root . ''; case 'root_folder': return ''; case 'data_folder': return 'data'; case 'loglevel': return 3; case 'debug_mode': return true; case 'email_enabled': return false; case 'db_class': return 'mysql'; case 'db_host': return 'localhost'; case 'system_online': return true; case 'allow_registration': return true; case 'prefix': return 'ts_'; case 'encryption_class': return 'mcrypt'; case 'encryption_algorithm': return 'blowfish'; case 'encryption_mode': return 'ecb'; case 'system_secret': include_once 'functions/getRandomString.func.php'; return getRandomString(20); } return NULL; }
function install($adminPassword, $email, $timezone) { global $Language; $stdOut = array(); if (!date_default_timezone_set($timezone)) { date_default_timezone_set('UTC'); } $currentDate = Date::current(DB_DATE_FORMAT); // ============================================================================ // Create directories // ============================================================================ // 7=read,write,execute | 5=read,execute $dirpermissions = 0755; $firstPostSlug = 'first-post'; if (!mkdir(PATH_POSTS . $firstPostSlug, $dirpermissions, true)) { $errorText = 'Error when trying to created the directory=>' . PATH_POSTS . $firstPostSlug; error_log($errorText, 0); } if (!mkdir(PATH_PAGES . 'error', $dirpermissions, true)) { $errorText = 'Error when trying to created the directory=>' . PATH_PAGES . 'error'; error_log($errorText, 0); } if (!mkdir(PATH_PAGES . 'about', $dirpermissions, true)) { $errorText = 'Error when trying to created the directory=>' . PATH_PAGES . 'about'; error_log($errorText, 0); } if (!mkdir(PATH_PLUGINS_DATABASES . 'pages', $dirpermissions, true)) { $errorText = 'Error when trying to created the directory=>' . PATH_PLUGINS_DATABASES . 'pages'; error_log($errorText, 0); } if (!mkdir(PATH_PLUGINS_DATABASES . 'simplemde', $dirpermissions, true)) { $errorText = 'Error when trying to created the directory=>' . PATH_PLUGINS_DATABASES . 'simplemde'; error_log($errorText, 0); } if (!mkdir(PATH_PLUGINS_DATABASES . 'tags', $dirpermissions, true)) { $errorText = 'Error when trying to created the directory=>' . PATH_PLUGINS_DATABASES . 'tags'; error_log($errorText, 0); } if (!mkdir(PATH_PLUGINS_DATABASES . 'about', $dirpermissions, true)) { $errorText = 'Error when trying to created the directory=>' . PATH_PLUGINS_DATABASES . 'about'; error_log($errorText, 0); } if (!mkdir(PATH_UPLOADS_PROFILES, $dirpermissions, true)) { $errorText = 'Error when trying to created the directory=>' . PATH_UPLOADS_PROFILES; error_log($errorText, 0); } if (!mkdir(PATH_TMP, $dirpermissions, true)) { $errorText = 'Error when trying to created the directory=>' . PATH_TMP; error_log($errorText, 0); } if (!mkdir(PATH_UPLOADS_THUMBNAILS, $dirpermissions, true)) { $errorText = 'Error when trying to created the directory=>' . PATH_UPLOADS_THUMBNAILS; error_log($errorText, 0); } // ============================================================================ // Create files // ============================================================================ $dataHead = "<?php defined('BLUDIT') or die('Bludit CMS.'); ?>" . PHP_EOL; // File pages.php $data = array('error' => array('description' => 'Error page', 'username' => 'admin', 'tags' => array(), 'status' => 'published', 'date' => $currentDate, 'position' => 0), 'about' => array('description' => $Language->get('About your site or yourself'), 'username' => 'admin', 'tags' => array(), 'status' => 'published', 'date' => $currentDate, 'position' => 1)); file_put_contents(PATH_DATABASES . 'pages.php', $dataHead . json_encode($data, JSON_PRETTY_PRINT), LOCK_EX); // File posts.php $data = array($firstPostSlug => array('description' => $Language->get('Welcome to Bludit'), 'username' => 'admin', 'status' => 'published', 'tags' => array('bludit' => 'Bludit', 'cms' => 'CMS', 'flat-files' => 'Flat files'), 'allowComments' => 'false', 'date' => $currentDate)); file_put_contents(PATH_DATABASES . 'posts.php', $dataHead . json_encode($data, JSON_PRETTY_PRINT), LOCK_EX); // File site.php $data = array('title' => 'BLUDIT', 'slogan' => 'CMS', 'description' => '', 'footer' => 'Copyright © ' . Date::current('Y'), 'language' => $Language->getCurrentLocale(), 'locale' => $Language->getCurrentLocale(), 'timezone' => $timezone, 'theme' => 'log', 'adminTheme' => 'default', 'homepage' => '', 'postsperpage' => '6', 'uriPost' => '/post/', 'uriPage' => '/', 'uriTag' => '/tag/', 'url' => PROTOCOL . DOMAIN . HTML_PATH_ROOT, 'emailFrom' => 'no-reply@' . DOMAIN); file_put_contents(PATH_DATABASES . 'site.php', $dataHead . json_encode($data, JSON_PRETTY_PRINT), LOCK_EX); // File users.php $salt = getRandomString(); $passwordHash = sha1($adminPassword . $salt); $data = array('admin' => array('firstName' => $Language->get('Administrator'), 'lastName' => '', 'twitter' => '', 'role' => 'admin', 'password' => $passwordHash, 'salt' => $salt, 'email' => $email, 'registered' => $currentDate)); file_put_contents(PATH_DATABASES . 'users.php', $dataHead . json_encode($data, JSON_PRETTY_PRINT), LOCK_EX); // File security.php $randomKey = getRandomString(); $randomKey = sha1($randomKey); $data = array('key1' => $randomKey, 'minutesBlocked' => 5, 'numberFailuresAllowed' => 10, 'blackList' => array()); file_put_contents(PATH_DATABASES . 'security.php', $dataHead . json_encode($data, JSON_PRETTY_PRINT), LOCK_EX); // File tags.php file_put_contents(PATH_DATABASES . 'tags.php', $dataHead . json_encode(array('postsIndex' => array('bludit' => array('name' => 'Bludit', 'posts' => array('first-post')), 'cms' => array('name' => 'CMS', 'posts' => array('first-post')), 'flat-files' => array('name' => 'Flat files', 'posts' => array('first-post'))), 'pagesIndex' => array()), JSON_PRETTY_PRINT), LOCK_EX); // PLUGINS // File plugins/pages/db.php file_put_contents(PATH_PLUGINS_DATABASES . 'pages' . DS . 'db.php', $dataHead . json_encode(array('position' => 0, 'homeLink' => true, 'label' => $Language->get('Pages')), JSON_PRETTY_PRINT), LOCK_EX); // File plugins/about/db.php file_put_contents(PATH_PLUGINS_DATABASES . 'about' . DS . 'db.php', $dataHead . json_encode(array('position' => 0, 'label' => $Language->get('About'), 'text' => $Language->get('this-is-a-brief-description-of-yourself-our-your-site')), JSON_PRETTY_PRINT), LOCK_EX); // File plugins/simplemde/db.php file_put_contents(PATH_PLUGINS_DATABASES . 'simplemde' . DS . 'db.php', $dataHead . json_encode(array('position' => 0, 'tabSize' => 4, 'toolbar' => '"bold", "italic", "heading", "|", "quote", "unordered-list", "|", "link", "image", "code", "horizontal-rule", "|", "preview", "side-by-side", "fullscreen", "guide"'), JSON_PRETTY_PRINT), LOCK_EX); // File plugins/tags/db.php file_put_contents(PATH_PLUGINS_DATABASES . 'tags' . DS . 'db.php', $dataHead . json_encode(array('position' => 0, 'label' => $Language->get('Tags')), JSON_PRETTY_PRINT), LOCK_EX); // File FILENAME for error page $data = 'Title: ' . $Language->get('Error') . ' Content: ' . $Language->get('The page has not been found'); file_put_contents(PATH_PAGES . 'error' . DS . FILENAME, $data, LOCK_EX); // File FILENAME for about page $data = 'Title: ' . $Language->get('About') . ' Content: ' . $Language->get('the-about-page-is-very-important') . ' ' . $Language->get('change-this-pages-content-on-the-admin-panel'); file_put_contents(PATH_PAGES . 'about' . DS . FILENAME, $data, LOCK_EX); // File FILENAME for welcome post $text1 = Text::replaceAssoc(array('{{ADMIN_AREA_LINK}}' => PROTOCOL . DOMAIN . HTML_PATH_ROOT . 'admin'), $Language->get('Manage your Bludit from the admin panel')); $data = 'Title: ' . $Language->get('First post') . ' Content: ## ' . $Language->get('Whats next') . ' - ' . $text1 . ' - ' . $Language->get('Follow Bludit on') . ' [Twitter](https://twitter.com/bludit) / [Facebook](https://www.facebook.com/bluditcms) / [Google+](https://plus.google.com/+Bluditcms) - ' . $Language->get('Chat with developers and users on Gitter') . ' - ' . $Language->get('Visit the support forum') . ' - ' . $Language->get('Read the documentation for more information') . ' - ' . $Language->get('Share with your friends and enjoy'); file_put_contents(PATH_POSTS . $firstPostSlug . DS . FILENAME, $data, LOCK_EX); return true; }
if (count($_POST) > 0) { $arr = $_POST; $existemail = $dbObj->fun_check_email_admin_existance1($arr['email']); if ($existemail) { function getRandomString($length = 6) { $validCharacters = "abcdefghijklmnopqrstuxyvwzABCDEFGHIJKLMNOPQRSTUXYVWZ123456789"; $validCharNumber = strlen($validCharacters); $result = ""; for ($i = 0; $i < $length; $i++) { $index = mt_rand(0, $validCharNumber - 1); $result .= $validCharacters[$index]; } return $result; } $arr['reset_key'] = getRandomString(); $lastID = $dbObj->update_data(TABLE_USERS, 'email', $arr, md5($_POST['email'])); $mail = new PHPMailer(); $mail->From = "*****@*****.**"; $mail->AddAddress($_POST['email']); $mail->Subject = "To reset password"; $mail->IsHTML(true); $mail->Body = "<b><font size='+2' color='red'>Reset Password</font></b><br><br>\n\t\t <br>Click the link below to reset your password<br>\n\t\t http://" . $_SERVER['HTTP_HOST'] . "/94/jwasser/forgot.php?key=" . $arr['reset_key'] . "<br><br>"; //echo $mail->Body ;die; if (!$mail->Send()) { $_SESSION['msg'] = 'Mail was not sent.'; redirectURL(SITE_ADMIN_URL . "profile-login.php"); } else { $_SESSION['msg'] = "Check your email INBOX to reset your password"; redirectURL(SITE_ADMIN_URL . "profile-login.php"); }
/** * */ function tryChangePassword($old_pass, $new_pass) { $userid = $this->getUserid(); if ($this->isPasswordValid($userid, $old_pass)) { $salt = getRandomString(4); $password_hash = md5($salt . $new_pass); $query = query("UPDATE {$this->user_tablename} SET pass = '******', salt = '" . db()->escape_string($salt) . "' WHERE id = '" . $userid . "'"); return true; } return false; }
/** * Executes the installation * * @return boolean */ public function database(Container $application) { $config = $this->config; //Stores all user information in the database; $dbName = $application->input->getString("dbname", "", "post"); $dbPass = $application->input->getString("dbpassword", "", "post"); $dbHost = $application->input->getString("dbhost", "", "post"); $dbPref = $application->input->getString("dbtableprefix", "", "post"); $dbUser = $application->input->getString("dbusername", "", "post"); $dbDriver = $application->input->getString("dbdriver", "MySQLi", "post"); $dbPort = $application->input->getInt("dbport", "", "post"); if (empty($dbName)) { throw new \Exception(t("Database Name is required to proceed.")); return false; } if (empty($dbDriver)) { throw new \Exception(t("Database Driver Type is required to proceed.")); return false; } if (empty($dbUser)) { throw new \Exception(t("Database username is required to proceed")); return false; } if (empty($dbHost)) { throw new \Exception(t("Please provide a link to your database host. If using SQLite, provide a path to the SQLite database as host")); return false; } $config->set("setup.database.host", $dbHost); $config->set("setup.database.prefix", $dbPref); $config->set("setup.database.user", $dbUser); $config->set("setup.database.password", $dbPass); $config->set("setup.database.name", $dbName); $config->set("setup.database.driver", strtolower($dbDriver)); $config->set("setup.database.port", intval($dbPort)); //Try connect to the database with these details? try { $application->createInstance("database", [$application->config->get("setup.database.driver"), $application->config->get("setup.database")]); } catch (Exception $exception) { //@TODO do something with this exception; return false; } //@TODO run the install.sql script on the connected database $schema = new Schema(); //print_r($schema::$database); if (!$schema->createTables($application->database)) { echo "wtf"; return false; } //generate encryption key $encryptor = $this->encryptor; $encryptKey = $encryptor->generateKey(time() . getRandomString(5)); $config->set("setup.encrypt.key", $encryptKey); if (!$config->saveParams()) { throw new Exception("could not save config"); return false; } return true; }
public function getText(PostsProcessor $processor, $postId, $takeTextFromPost) { if (!$takeTextFromPost) { return getRandomString(TestManager::RND_STRING_LEN); } $ident = $processor->getPostType() . '_' . $postId; $matches = array(); if (array_key_exists($ident, $this->postData)) { $matches = $this->postData[$ident]; } else { $content = $processor->getPostContentProvider($postId)->getPostContent()->getContent(); preg_match_all("/<p[^>]*>([^<]*)<\\/p>/si", $content, $matches, PREG_PATTERN_ORDER); $matches = $matches[1]; $this->postData[$ident] = $matches; } $cnt = count($matches); $text = trim($cnt == 0 ? getRandomString(TestManager::RND_STRING_LEN) : $matches[rand(0, $cnt - 1)]); return $text ? UserInputTools::safeLongText($text) : getRandomString(TestManager::RND_STRING_LEN); }
if (isset($_GET['login']) && eF_checkParameter($_GET['login'], 'login')) { $user = EfrontUserFactory::factory($_GET['login']); if ($user->user['autologin'] == "") { $token = getRandomString(20, true); $user->user['autologin'] = $token; } else { $user->user['autologin'] = ""; } $user->persist(); echo $token; } else { if (isset($_GET['addAll'])) { isset($_GET['filter']) ? $usersArray = eF_filterData($usersArray, $_GET['filter']) : null; foreach ($usersArray as $key => $value) { if ($value['autologin'] == "") { $autologin = getRandomString(20, true); eF_updateTableData("users", array('autologin' => $autologin), "login='******'"); } } } else { if (isset($_GET['removeAll'])) { if (isset($_GET['filter'])) { $usersArray = eF_filterData($usersArray, $_GET['filter']); $queryString = "'" . implode("','", array_keys($usersArray)) . "'"; eF_updateTableData("users", array('autologin' => ""), "login IN (" . $queryString . ")"); } else { eF_updateTableData("users", array('autologin' => ""), "login !=''"); } } } }
$page = isset($_REQUEST["gpage"]) ? $_REQUEST["gpage"] : 1; $gpa = 0; if ($page > 1) { if (!isset($_REQUEST["gpa"])) { trigger_error("required parameter gpa is missing"); } else { $gpa = $_REQUEST["gpa"]; } } $records = array(); $count = 0; while ($count < 25) { $record = ""; $words = 10 * mt_rand(1, 6); while ($words > 0) { $record .= " " . getRandomString(); $words--; } $records[] = $record; $count++; } $gpa = $gpa + $count; $nextUrl = "/test/infinite/posts2.php?gpage=" . ($page + 1) . "&gpa=" . $gpa; ?> <!DOCTYPE html> <html> <head> <title> infinite scrolling applied to PHP pagination with performance </title> <meta charset="utf-8">
<?php require_once 'DBaccess.php'; require_once 'functions.php'; function getRandomString($nLengthRequired = 4) { $sCharList = “abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_”; mt_srand(); $sRes = “”; for ($i = 0; $i < $nLengthRequired; $i++) { $sRes .= $sCharList[mt_rand(0, strlen($sCharList) - 1)]; } return $sRes; } for ($i = 0; $i < 20; $i++) { $name = getRandomString(); $sql = sprintf('INSERT INTO users SET name="%s", created=NOW(), modified=NOW()', r($name)); mysql_query($sql) or die(mysql_error()); } header('Location: index.php');