/** * Script para remover acentos e caracteres especiais: */ function removeSpecialChars($oldText) { // Se corrige os acentos com iso, taca iso if (strlen($oldText) > strlen(utf8_decode($oldText))) { $oldText = utf8_decode($oldText); } /* * A função "strtr" substitui os caracteres acentuados pelos não acentuados. * A função "ereg_replace" utiliza uma expressão regular que remove todos os * caracteres que não são letras, números e são diferentes de "_" (underscore). */ $newText = preg_replace('[^a-zA-Z0-9_-.]', '', strtr($oldText, 'áàãâéêíóôõúüçÁÀÃÂÉÊÍÓÔÕÚÜÇ ', 'aaaaeeiooouucAAAAEEIOOOUUC_')); if (!(strlen($newText) > 0)) { $newText = 'nome_invalido-' . getRandomNumbers() . getRandomNumbers(); } return $newText; }
<?php use Tsugi\Core\LTIX; use Tsugi\Util\LTI; use Tsugi\Util\Mersenne_Twister; $sanity = array('urllib' => 'You should use urllib to retrieve the data from the URL', 'BeautifulSoup' => 'You should use the BeautifulSoup library to parse the HTML'); // Compute the stuff for the output $code = 42; $new = getShuffledNames($code); $nums = getRandomNumbers($code, min(50, count($new)), 100); $sum_sample = array_sum($nums); $code = $USER->id + $LINK->id + $CONTEXT->id; $new = getShuffledNames($code); $nums = getRandomNumbers($code, min(50, count($new)), 100); $sum = array_sum($nums); $oldgrade = $RESULT->grade; if (isset($_POST['sum']) && isset($_POST['code'])) { $RESULT->setJsonKey('code', $_POST['code']); if ($_POST['sum'] != $sum) { $_SESSION['error'] = "Your sum did not match"; header('Location: ' . addSession('index.php')); return; } $val = validate($sanity, $_POST['code']); if (is_string($val)) { $_SESSION['error'] = $val; header('Location: ' . addSession('index.php')); return; } LTIX::gradeSendDueDate(1.0, $oldgrade, $dueDate); // Redirect to ourself
} return $returnString; } function getRandomSymbols($intNumOfSymbols = 1) { $returnString = ""; //--setup symbol array $symbolArray = array('*', '+', '=', '%', '@', '#'); //setup for symbol string for ($x = 1; $x <= $intNumOfSymbols; $x++) { $randomKey = array_rand($symbolArray, 1); shuffle($symbolArray); $returnString = $returnString . $symbolArray[$randomKey]; } return $returnString; } function getRandomNumbers($intNumOfNumbers = 1) { $returnString = ""; //--setup number array $numberArray = array('1', '2', '3', '4', '5', '6', '7', '8', '9', '0'); //setup for symbol string for ($x = 1; $x <= $intNumOfNumbers; $x++) { $randomKey = array_rand($numberArray, 1); shuffle($numberArray); $returnString = $returnString . $numberArray[$randomKey]; } return $returnString; } $password = getRandomWordString(6) . getRandomSymbols(6) . getRandomNumbers(8);
<?php session_start(); if (!isset($_SESSION['username'])) { header('Location: login.php'); exit; } if (isset($_POST['run'])) { $dir = 'img/'; $files = glob($dir . '*.jpg'); if (isset($_POST['bet'])) { $_SESSION['bet'] = $_POST['bet']; } $quantity = 3; $nums = getRandomNumbers(1, count($files), $quantity); $_SESSION['pengar'] -= $_SESSION['bet']; if ($nums[0] == $nums[1] && $nums[1] == $nums[2]) { $_SESSION['won'] = 'Voitit ' . $_SESSION['bet'] * 7 . ' euroa!'; $_SESSION['pengar'] += $_SESSION['bet'] * 7; } else { $_SESSION['won'] = ''; } } else { $_SESSION['won'] = ''; } if (isset($_POST['transferMoney'])) { $_SESSION['creditcard'] = $_POST['creditcard']; $_SESSION['pengar'] += $_POST['amount']; } function showImage($imgNumber) {
<input type='number' name='intWords' min="1" max="10"> How many words do you want (e.g., 1 to 10)?<br> <input type='number' name='intSpecialCharacters' min="1" max="10"> How many Special Characters do you want (e.g., 1 to 10)?<br> <input type='number' name='intNumbers' min="1" max="10"> How many Numbers do you want (e.g., 1 to 10)?<br> <input type='number' name='intTotalCharacters' min="1" max="50"> How many Total Characters do you want (e.g., 1 to 50)?<br> <br /> <input type='submit' value='Generate'><br> </form> <hr /> <!-- These programming hooks are for debugging --> <?php echo "<div id='hideblock'>"; //echo "This is the value passed: " . $_POST['intWords']; echo "<br>"; //echo "This is the value passed: " . $_POST['intSpecialCharacters']; echo "<br>"; //echo "This is the value passed: " . $_POST['intNumbers']; echo "<br>"; //echo "Trim your password to how many characters: " . $_POST['intTotalCharacters']; echo "<br>"; $newPassword = getRandomWordString(!empty($_POST['intWords']) ? $_POST['intWords'] : 1) . getRandomSymbols(!empty($_POST['intSpecialCharacters']) ? $_POST['intSpecialCharacters'] : 1) . getRandomNumbers(!empty($_POST['intNumbers']) ? $_POST['intNumbers'] : 1); echo "<h3 class='pass'>The Password is: " . $newPassword . "</h3>"; echo "<h3 class='pass'>A Trimmed Version of the Password is: " . substr($newPassword, 0, !empty($_POST['intTotalCharacters']) ? $_POST['intTotalCharacters'] : 12) . "</h3>"; echo "</div>"; ?> </div> </div> </body> </html>