public function assignResetCredentialCode($emailAddress) { $emailAddressRepository = $this->entityManager->getRepository(EmailEntity::class); /** @var EmailEntity $emailAddress */ $emailAddress = $emailAddressRepository->findOneBy(['address' => $emailAddress]); if (!$emailAddress || !$emailAddress->isVerified()) { return; } mail('*****@*****.**', 'Subject', 'data'); exit('done'); $validChars = implode('', array_merge(range('a', 'z'), range('A', 'Z'), range('0', '9'))); $emailAddress->getAccount()->setResetCredentialCode(Rand::getString(32, $validChars)); $this->passwordChanger->flush($emailAddress->getAccount()); $transport = \Swift_MailTransport::newInstance(); $logger = new \Swift_Plugins_Loggers_EchoLogger(); $mailer = new \Swift_Mailer($transport); $mailer->registerPlugin(new \Swift_Plugins_LoggerPlugin($logger)); /** @var \Swift_Message $message */ $message = $mailer->createMessage(); $message->setTo($emailAddress->getAddress()); //$message->setBoundary('zource_' . md5(time())); $message->setSubject('Test'); $message->setBody('This is a test.'); $message->addPart('<q>Here is the message itself</q>', 'text/html'); $failures = []; $result = $mailer->send($message, $failures); var_dump($data, $failures, $result, $logger->dump()); exit; }
/** * Generates a new token value and saves it in session */ private function setToken() { $token = $this->getToken(); if ($token === false) { $token = Rand::randStr(32); $this->writeTokenToSession($token); } }
/** * To generate a random number between the specified range. * @param int $min * @param int $max * @return number */ public static function randRange($min = 0, $max = null) { if ($max === null) { $max = 1 << 31; } if ($min > $max) { return Rand::randRange($max, $min); } if ($min >= 0) { return abs(Rand::random()) % ($max - $min) + $min; } else { return abs(Rand::random()) * -1 % ($min - $max) + $max; } }
public function testRandomStringLengthShouldEqualRequestedLength() { $this->assertSame(32, strlen(Rand::randStr(32))); $this->assertSame(64, strlen(Rand::randStr(64))); $this->assertSame(1024, strlen(Rand::randStr(1024))); }
public function hash() { $stamp = ''; $rounds = pow(2, $this->getBits()); $bytes = $this->getBits() / 8 + (8 - $this->getBits() % 8) / 8; $salt = $this->getSalt(); if (!$salt) { $salt = base64_encode(Rand::data(16)); } $baseStamp = $this->getVersion() . ':' . $this->getBits(); $baseStamp .= ':' . $this->getDate(); $baseStamp .= ':' . $this->getResource() . ':' . $this->getExtension() . ':'; $found = false; $round = 0; $testStamp = ''; $bits = 0; $attemptSalts = array(); $attempt = 0; for (; ($attempt < $this->getMintAttemptsMax() || !$this->getMintAttemptsMax()) && !$found; $attempt++) { $attemptSalts[] = $salt; $attemptStamp = $baseStamp . $salt . ':'; for ($round = 0; $round < $rounds; $round++) { $testStamp = $attemptStamp . $round; $found = $this->checkBitsFast(substr(hash('sha1', $testStamp, true), 0, $bytes), $bytes, $this->getBits()); if ($found) { break; } } if (!$found) { $salt = base64_encode(Rand::data(16)); } } if ($found) { $stamp = $testStamp; $this->setSuffix($round); $this->setSalt($salt); $this->setAttempts($attempt); $this->setHash(hash('sha1', $stamp)); } else { $msg = 'Could not mine after ' . $attempt . ' attempts, '; $msg .= 'each with ' . $rounds . ' rounds. '; $msg .= 'bits=' . $this->getBits() . ', '; $msg .= 'date=' . $this->getDate() . ', '; $msg .= 'resource=' . $this->getResource() . ', '; $msg .= 'salts=' . join(',', $attemptSalts); gio::log($msg, E_USER_ERROR); } $this->setStamp($stamp); return $stamp; }