public function testGenerateToken() { $tokenGenerator = new TokenGenerator(); $token = $tokenGenerator->generateToken(); $this->assertTrue(is_string($token)); $this->assertGreaterThan(0, strlen($token)); }
public function handle(FormInterface $form, Request $request) { $form->handleRequest($request); if (!$form->isValid()) { return false; } $data = $form->getData(); if ($form->isSubmitted()) { $user = $this->userManager->findUserByEmail($data['email']); if (is_null($user)) { $form->addError(new FormError($this->translator->trans('security.resetting.request.errors.email_not_found'))); return false; } if ($user->isPasswordRequestNonExpired($this->tokenTll)) { $form->addError(new FormError($this->translator->trans('security.resetting.request.errors.password_already_requested'))); return false; } if ($user->getConfirmationToken() === null) { $user->setConfirmationToken($this->tokenGenerator->generateToken()); } $user->setPasswordRequestedAt(new \DateTime()); $this->userManager->resettingRequest($user); } return true; }
public function requestformAction() { $tokenObj = new TokenGenerator(); try { $userID = $this->_getParam("userID"); $token = $tokenObj->getToken($userID); $this->view->pToken = DataFormat::hexstr($token->pToken); $this->view->timestamp = $token->timestamp; $warmupObj = new Warmup(); $warmupObj->warmup($userID); } catch (Exception $e) { print_r($e); } $this->view->formaction = "/billing/bill"; $this->render('billingex'); }
<head> <title></title> <link rel="stylesheet" type="text/css" href="symptom_selector/selector.css?v=1"> <link rel="stylesheet" type="text/css" href="symptom_selector/fontawesome/assets/css/font-awesome.min.css" /> <script src="libs/jquery-1.12.2.min.js"></script> <script src="libs/json2.js"></script><!-- json for ie7 --> <script src="libs/jquery.imagemapster.min.js?v=1.1"></script> <script src="libs/typeahead.bundle.js"></script> <script src="symptom_selector/selector.js?v=3.3"></script> <?php // session_start(); // this causes some issues with certain servers, try this if it's working with this line or not. if (!isset($_SESSION['userToken']) || !isset($_SESSION['tokenExpireTime']) || time() >= $_SESSION['tokenExpireTime']) { require 'token_generator.php'; $tokenGenerator = new TokenGenerator("YOUR_USERNAME", "YOUR_PASSWORD", "https://sandbox-authservice.priaid.ch/login"); $token = $tokenGenerator->loadToken(); $_SESSION['userToken'] = $token->{'Token'}; $_SESSION['tokenExpireTime'] = time() + $token->{'ValidThrough'}; } $token = $_SESSION['userToken']; ?> <script type="text/javascript"> var userToken = <?php echo "'" . $token . "'"; ?> ; $(document).ready(function () {
private function generateToken() { //get from memcached first $key = $this->getCachedKey(); $dataToken = $this->_cache->getTokenCache($key); if ($dataToken == FALSE) { $tokenObj = new TokenGenerator(); $token = $tokenObj->getToken($this->userID); $pToken = DataFormat::hexstr($token->pToken); $this->view->pToken = $pToken; $dataToken = array('billstat' => 0, 'tokenkey' => $pToken); //billstat:0-chua xac nhan,1-hoan thanh xac nhan $this->_cache->setTokenCache($key, $dataToken); return true; } else { if ($dataToken['billstat'] == "1") { return false; } $this->view->pToken = $dataToken['tokenkey']; return true; } }
/** * @param string $payload */ public function fromPayload($payload) { $this->token = $this->generator->generate($payload); }
public function handleBALANCE($params) { $suppliedToken = $params["token"]; if (TokenGenerator::checkExpired($suppliedToken)) { $this->addError("Your token has expired or does not exist, please login again."); $this->handleLOGOUT(["token" => $suppliedToken]); } global $dbConn; global $bitcoin; echo TokenGenerator::getUsernameFromToken($suppliedToken); return $bitcoin->getbalance(TokenGenerator::getUsernameFromToken($suppliedToken)); }
/** * Check if token is valid. * * @param string $token * @param mixed $value * * @return bool */ public function isValid($token, $value) { return $token === $this->generator->generate($value); }
<?php define('SECRET_KEY', '123456Aa?'); include './JWT.php'; try { $generator = new TokenGenerator(SECRET_KEY); $token = $generator->setData(array('admin' => true, 'uid' => '9999', 'data' => ['id' => 1, 'name' => 'abc', 'age' => 22]))->setOptions(array('expires' => time() + 3600))->create(); } catch (TokenException $e) { echo "Error: " . $e->getMessage(); } echo $token; try { $p = JWT::decode($token, SECRET_KEY, ['HS256']); var_dump($p); } catch (Exception $e) { echo "Error: " . $e->getMessage(); }
public function simulate() { if (!$this->checkRequiredParameters()) { return; } $tokenGenerator = new TokenGenerator($this->config['username'], $this->config['password'], $this->config['authServiceUrl']); $token = $tokenGenerator->loadToken(); if (!isset($token)) { exit; } $this->diagnosisClient = new DiagnosisClient($token, $this->config['healthServiceUrl'], 'en-gb'); print '<html><body>'; print '<h3>Body locations</h3>'; $bodyLocations = $this->diagnosisClient->loadBodyLocations(); if (!isset($bodyLocations)) { exit; } $this->printSimpleObject($bodyLocations); // get random body location $locRandomIndex = rand(0, count($bodyLocations) - 1); $locRandomId = $bodyLocations[$locRandomIndex]['ID']; $locRandomName = $bodyLocations[$locRandomIndex]['Name']; $bodySublocations = $this->diagnosisClient->loadBodySublocations($locRandomId); if (!isset($bodySublocations)) { exit; } print "<h3>Body Subocations for {$locRandomName}({$locRandomId})</h3>"; $this->printSimpleObject($bodySublocations); // get random body sublocation $sublocRandomIndex = rand(0, count($bodySublocations) - 1); $sublocRandomId = $bodySublocations[$sublocRandomIndex]['ID']; $sublocRandomName = $bodySublocations[$sublocRandomIndex]['Name']; $symptoms = $this->diagnosisClient->loadSublocationSymptoms($sublocRandomId, 'man'); print "<h3>Symptoms in body sublocation {$sublocRandomName}({$sublocRandomId})</h3>"; if (!isset($symptoms)) { exit; } if (count($symptoms) == 0) { die("No symptoms for selected body sublocation"); } $this->printSimpleObject($symptoms); // get diagnosis $randomSymptomIndex = rand(0, count($symptoms) - 1); $randomSymptomId = $symptoms[$randomSymptomIndex]['ID']; $randomSymptomName = $symptoms[$randomSymptomIndex]['Name']; $selectedSymptoms = array($randomSymptomId); $diagnosis = $this->diagnosisClient->loadDiagnosis($selectedSymptoms, 'male', 1988); if (!isset($diagnosis)) { exit; } print "<h3>Calculated diagnosis for {$randomSymptomName}({$randomSymptomId})</h3>"; $this->printDiagnosis($diagnosis); // get specialisations $specialisations = $this->diagnosisClient->loadSpecialisations($selectedSymptoms, 'male', 1988); if (!isset($specialisations)) { exit; } print "<h3>Calculated specialisations for {$randomSymptomName}({$randomSymptomId})</h3>"; $this->printSpecialisations($specialisations); // get proposed symptoms $proposedSymptoms = $this->diagnosisClient->loadProposedSymptoms($selectedSymptoms, 'male', 1988); if (!isset($proposedSymptoms)) { exit; } print "<h3>Proposed symptoms for selected {$randomSymptomName}({$randomSymptomId})</h3>"; $this->printSimpleObject($proposedSymptoms); // get red flag text $redFlagText = $this->diagnosisClient->loadRedFlag($randomSymptomId); if (!isset($redFlagText)) { exit; } print "<h3>Red flag text for selected {$randomSymptomName}({$randomSymptomId})</h3>"; print $redFlagText; // get issue info reset($diagnosis); while (list($key, $val) = each($diagnosis)) { $this->loadIssueInfo($val['Issue']['ID']); } print '</body></html>'; }