function generateArraysAndPrintThem() { for ($c = 0; $c < 10; $c++) { $randArray = generateRandom(); $avg = calcAvg($randArray); echo $avg . '<br>'; // or: echo calcAvg(generateRandom()); (we don't need to bother storing these as values intermittently } }
<?php session_start(); header("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1 header("Expires: Sat, 26 Jul 1997 05:00:00 GMT"); // Date in the past header('Content-type: image/svg+xml'); $rText = generateRandom(); $_SESSION['captcha'] = $rText; /**Generates a random text*/ function generateRandom($length = 6, $vals = 'abchefghjkmnpqrstuvwxyz0123456789') { $s = ""; while (strlen($s) < $length) { mt_getrandmax(); $num = rand() % strlen($vals); $s .= substr($vals, $num + 4, 1); } return $s; } /**Converts a string to SVG*/ function stringToSVG($str) { $result = ''; $glyphs = array(); $x = 5; //start point --> x $y = 30; //start point --> y //generates glyphs
/** * parseSearchResponseXML * * Разбор ответа сервиса поиска. * * Собственно просто преобразует данные из SimpleXMLObject в массив, * также добавляет к каждой записи уникальный ReferenceID. В данном примере * в этом качестве будет выступать случайным образом сгенерированная строка. * В реальном использовании Reference обозначает ID конкретной записи в контексте * системы, в которой используются сервисы (например, id из таблицы БД, с которой * сопоставлено предложение) * * @param SimpleXMLObject XML-объект * @return array возвращает массив данных */ function parseSearchResponseXML($xml) { $data = array(); foreach ($xml->rows->row as $row) { $_row = array(); foreach ($row as $key => $field) { $_row[(string) $key] = (string) $field; } $_row['Reference'] = generateRandom(9); $data[] = $_row; } return $data; }
function generateSalt() { return generateRandom(SALT_CHARACTERS, 22); }
function invitationMail() { $this->load->model('securemodel', 'secure'); $eventId = $_POST['eventId']; $event = $this->consultants->getEnquiryById($eventId); $randomCode = generateRandom(10); $this->secure->setEventRandomCode($eventId, $randomCode); $event_link = my_site_url() . 'welcome/event/' . $eventId . '/' . $randomCode; $emailTemplate = $this->secure->getEmailTemplateById('16'); $musician = $_POST['musiciansendinvitation']; if (!$musician) { return; exit; } $eventData = $this->musicians->getMusicialnById($musician); $config['protocol'] = 'mail'; $config['wordwrap'] = FALSE; $config['mailtype'] = 'html'; $config['charset'] = 'utf-8'; $config['crlf'] = "\r\n"; $config['newline'] = "\r\n"; $this->load->library('email', $config); $subject = $emailTemplate['subject']; $massage = $emailTemplate['body']; $randomCode = generateRandom(10); $this->secure->setEventRandomCode($eventId, $randomCode); $event_link = my_site_url() . 'welcome/event/' . $eventId . '/' . $randomCode; foreach ($eventData as $invite) { $this->email->from('*****@*****.**', 'Club Band'); $this->email->to($invite->email, $invite->first_name); $msg = str_replace(array('{$customer_first_name}', '{$customer_second_name}', '{$event_link}'), array($invite->first_name, $invite->last_name, $event_link), $massage); $resp = array(); $this->email->subject($subject); $this->email->message($msg); if ($this->email->send()) { $mail = 1; } else { $mail = 0; } } if ($mail) { $resp['process'] = 'success'; $resp['msg'] = 'Mail sent successfully'; } else { $resp['process'] = 'success'; $resp['msg'] = 'some mail not sent'; } echo json_encode($resp); }
function firstSaveExe() { if (!is_numeric($_SESSION['userId'])) { print "Wrong way"; exit; } //store current time $nowIsNow = now(); //save Diagram $diagram = new Diagram(); $diagram->title = trim($_REQUEST['title']); $diagram->description = trim($_REQUEST['description']); $diagram->public = $_REQUEST['public'] == true ? true : false; $diagram->createdDate = $nowIsNow; $diagram->lastUpdate = $nowIsNow; $diagram->size = strlen($_SESSION['tempDiagram']); //TODO: it might be not very accurate $delegate = new Delegate(); $token = ''; do { $token = generateRandom(6); } while ($delegate->diagramCountByHash($token) > 0); $diagram->hash = $token; $diagramId = $delegate->diagramCreate($diagram); //end save Diagram //create Dia file $diagramdata = new Diagramdata(); $diagramdata->diagramId = $diagramId; $diagramdata->type = Diagramdata::TYPE_DIA; $diagramdata->fileName = $diagramId . '.dia'; $fh = fopen(getStorageFolder() . '/' . $diagramId . '.dia', 'w'); $size = fwrite($fh, $_SESSION['tempDiagram']); fclose($fh); $diagramdata->fileSize = $size; $diagramdata->lastUpdate = $nowIsNow; $delegate->diagramdataCreate($diagramdata); //end Dia file //create SVG file $diagramdata = new Diagramdata(); $diagramdata->diagramId = $diagramId; $diagramdata->type = Diagramdata::TYPE_SVG; $diagramdata->fileName = $diagramId . '.svg'; $fh = fopen(getStorageFolder() . '/' . $diagramId . '.svg', 'w'); $size = fwrite($fh, $_SESSION['tempSVG']); fclose($fh); $diagramdata->fileSize = $size; $diagramdata->lastUpdate = $nowIsNow; $delegate->diagramdataCreate($diagramdata); //end SVG file //clean temporary diagram unset($_SESSION['tempDiagram']); unset($_SESSION['tempSVG']); //attach it to an user $userdiagram = new Userdiagram(); $userdiagram->diagramId = $diagramId; $userdiagram->userId = $_SESSION['userId']; $userdiagram->invitedDate = now(); $userdiagram->level = Userdiagram::LEVEL_AUTHOR; $userdiagram->status = Userdiagram::STATUS_ACCEPTED; $delegate->userdiagramCreate($userdiagram); redirect("../editor.php?diagramId=" . $diagramId); }
function generatePassword($len = 8) { return generateRandom($len); }
public static function doLogin($username, $submitted_password, $allow_login, $ip, $db) { if ($allow_login) { //Checking to see if the Username exists in the database $stmt = $db->prepare("SELECT * FROM user_accounts WHERE username=? LIMIT 1"); $stmt->execute(array($username)); $loginInfo = $stmt->fetch(PDO::FETCH_ASSOC); if (isset($loginInfo['uid'])) { if ($loginInfo['lockdown'] == 1) { setAlert('danger', 'Account Locked', 'This account has been locked by an Administrator, and cannot be used to log in.'); } elseif (password_verify($submitted_password, $loginInfo['password'])) { //Password is valid - Setting a blank session hash string $random_string = generateRandom(32); $_SESSION['sid'] = $random_string; $stmt = $db->prepare('INSERT INTO sessions (sid,uid,expire) VALUES (?,?,?)'); $stmt->execute(array($random_string, $loginInfo['uid'], time())); // Adding the most recent login time to the database information $stmt = $db->prepare('UPDATE user_accounts SET last_login = ? WHERE uid = ?'); $stmt->execute(array(time(), $loginInfo['uid'])); header('Location: ' . SITE_ADDRESS . '/dashboard'); } else { //The password is invalid - adding this request to the brute table User::bruteInsert($ip, $username, $db); $_SESSION['alert-subtext'] = "The username or password that you have entered is invalid."; } } else { //The username doesn't exist User::bruteInsert($ip, $username, $db); $_SESSION['alert-subtext'] = "The username or password that you have entered is invalid."; } } else { //This ip is brute-banned. They cannot log in. setAlert('danger', 'IP Address Banned', 'The IP Address you are connecting from has been temporarily banned due to repeated failed login attempts. Please try again later.'); } }
function sendLoginDetail() { $data['activeMenu'] = '/musician/musicians'; $data['title'] = 'Admin App::Musician'; $resp = array(); $uri = $this->uri->segment_array(); $musicianId = isset($uri[3]) ? $uri[3] : ''; $config['protocol'] = 'mail'; $config['wordwrap'] = FALSE; $config['mailtype'] = 'html'; $config['charset'] = 'utf-8'; $config['crlf'] = "\r\n"; $config['newline'] = "\r\n"; $this->load->library('email', $config); $this->email->from('*****@*****.**', 'Login Detail::CLUB BAND'); $msgbody = ''; if ($musicianId) { $musicianData = $this->consultants->getData('musician', array('id' => $musicianId)); $this->email->to($musicianData->email, $musicianData->first_name); $this->email->subject("Login Detail of CLUB BAND!"); if (!$musicianData->uid || $musicianData->uid == 0) { $ranuname = generateRandom(10); $ranpass = generateRandom(mt_rand(6, 15), 'password'); $musicianData->username = $ranuname; $musicianData->password = $ranpass; if ($this->consultants->updateMusicianData($musicianData)) { $msgbody .= 'Hi ' . $musicianData->first_name . ' ' . $musicianData->last_name . ',<br />'; $msgbody .= 'Here is you login credential for club band site. <br />'; $msgbody .= 'Username: '******' <br />'; $msgbody .= 'Password: '******' <br />'; $msgbody .= 'Please login on clubband using folloing url and see your activities.<br />'; $msgbody .= 'URL: <a href="' . my_site_url() . '">' . my_site_url() . '</a><br /><br />'; $msgbody .= 'Thanks,<br />CLUB BAND Team!'; } else { $resp['process'] = 'fail'; $resp['msg'] = "There is problem to generate username/password. Contact to webmaster"; } } else { $msgbody .= 'Hi ' . $musicianData->first_name . ' ' . $musicianData->last_name . ',<br />'; $msgbody .= 'Here is you login credential for club band site. <br />'; $msgbody .= 'Username: '******' <br />'; $msgbody .= 'Password: '******' <br />'; $msgbody .= 'Please login on clubband using folloing url and see your activities.<br />'; $msgbody .= 'URL: <a href="' . my_site_url() . '">' . my_site_url() . '</a><br /><br />'; $msgbody .= 'Thanks,<br />CLUB BAND Team!'; } } else { $resp['process'] = 'fail'; $resp['msg'] = "Musician's data not found"; } if ($msgbody) { $this->email->message($msgbody); if ($this->email->send()) { $resp['process'] = 'success'; $resp['msg'] = 'Mail sent successfully'; } else { $resp['process'] = 'fail'; $resp['msg'] = 'There is problem to send mail.'; } } echo json_encode($resp); }