function randomString() { require "vendor/autoload.php"; $factory = new RandomLib\Factory(); $generator = $factory->getGenerator(new SecurityLib\Strength(SecurityLib\Strength::MEDIUM)); return $generator->generateString(32, '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'); }
public function testMakeRequest() { $factory = new \RandomLib\Factory(); $generator = $factory->getGenerator(new \SecurityLib\Strength(\SecurityLib\Strength::MEDIUM)); $order_reference = $generator->generateString(32, 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'); $auth = $this->service->request('paypal/order'); $auth->populate(array('billing' => array('amount' => 100, 'amount[currencycode]' => 'GBP', 'email' => '*****@*****.**', 'name' => array('first' => 'Foo', 'last' => 'Bar')), 'merchant' => array('orderreference' => $order_reference, 'returnurl' => 'http://gajus.com/', 'cancelurl' => 'http://gajus.com/'), 'customer' => array('name' => array('first' => 'Foo', 'last' => 'Bar'), 'email' => '*****@*****.**')), '/requestblock/request'); $response = $auth->request(); $response_xml = $this->normaliseXML($response->getXML()); $this->assertXmlStringEqualsXmlString($this->normaliseXML($this->loadXML('request_paypal_order/test_make_request')), $response_xml); $transaction = $response->getTransaction(); $this->assertNotNull($transaction, 'PayPal Order transaction cannot be NULL.'); $this->assertNotNull($transaction['request_reference'], 'PayPal Order transaction must resolve "request_reference".'); $this->assertNotNull($transaction['transaction_type'], 'PayPal Order transaction must resolve "transaction_type".'); $this->assertNotNull($transaction['transaction_reference'], 'PayPal Order transaction must resolve "transaction_reference".'); $this->assertNotNull($transaction['timestamp'], 'PayPal Order transaction must resolve "timestamp".'); $this->assertNull($transaction['parent_transaction_reference'], 'PayPal Order transaction must not resolve "parent_transaction_reference".'); $this->assertNull($transaction['authcode'], 'PayPal Order transaction must not resolve "authcode".'); $this->assertNull($transaction['amount'], 'PayPal Order transaction must not resolve "amount.'); $this->assertNotNull($transaction['paypal_token'], 'PayPal Order transaction must resolve "paypal_token".'); $this->assertCount(8, $transaction, 'Transaction must consist of 8 entities.'); $this->assertSame('PAYPAL', $transaction['transaction_type'], '"transaction_type" must be "PAYPAL"'); $this->assertNull($response->getError(), 'Valid "paypal/order" must not produce an error.'); $this->assertNotNull($response->getRedirectUrl(), '"paypal/order" must redirect user.'); }
public function testMakeRequest() { $factory = new \RandomLib\Factory(); $generator = $factory->getGenerator(new \SecurityLib\Strength(\SecurityLib\Strength::MEDIUM)); $order_reference = $generator->generateString(32, 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'); $auth = $this->service->request('card/auth'); $auth->populate(array('billing' => array('amount' => 100, 'amount[currencycode]' => 'GBP', 'email' => '*****@*****.**', 'name' => array('first' => 'Foo', 'last' => 'Bar'), 'payment' => array('pan' => '4111110000000211', 'securitycode' => '123', 'expirydate' => '10/2031'), 'payment[type]' => 'VISA'), 'merchant' => array('orderreference' => $order_reference), 'customer' => array('name' => array('first' => 'Foo', 'last' => 'Bar'), 'email' => '*****@*****.**')), '/requestblock/request'); $response = $auth->request(); $transaction = $response->getTransaction(); $this->assertNotNull($transaction, 'Card Auth transaction cannot be NULL.'); $this->assertNotNull($transaction['request_reference'], 'Card Auth transaction must resolve "request_reference".'); $this->assertNotNull($transaction['transaction_type'], 'Card Auth transaction must resolve "transaction_type".'); $this->assertNotNull($transaction['transaction_reference'], 'Card Auth transaction must resolve "transaction_reference".'); $this->assertNotNull($transaction['timestamp'], 'Card Auth transaction must resolve "timestamp".'); $this->assertNull($transaction['parent_transaction_reference'], 'Card Auth transaction must not resolve "parent_transaction_reference".'); $this->assertNotNull($transaction['authcode'], 'Card Auth transaction must resolve "authcode".'); $this->assertNotNull($transaction['amount'], 'Card Auth transaction must resolve "amount.'); $this->assertNull($transaction['paypal_token'], 'Card Auth transaction must not resolve "paypal_token".'); $this->assertCount(8, $transaction, 'Transaction must consist of 8 entities.'); $this->assertSame('VISA', $transaction['transaction_type'], '"transaction_type" must be "VISA"'); // Valid "card/auth" must not produce an error. $this->assertNull($response->getError()); // "card/auth" must not redirect user. $this->assertNull($response->getRedirectUrl()); }
/** * @param RandomLib\Generator $generator */ public function __construct(\RandomLib\Generator $generator = null) { if ($generator === null) { $factory = new \RandomLib\Factory(); $this->generator = $factory->getGenerator(new \SecurityLib\Strength(\SecurityLib\Strength::MEDIUM)); } }
public function createState() { $factory = new \RandomLib\Factory(); $generator = $factory->getGenerator(new \SecurityLib\Strength(\SecurityLib\Strength::MEDIUM)); $state = $generator->generateString(128, "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"); return $state; }
/** * Retourne un chaîne aléatoire sécuritaire, url safe * @param integer $length Longeur de la chaîne à générer * @return string $string La chaîne générée */ public static function randomString($length = 80) { $possibleChars = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_-'; $factory = new \RandomLib\Factory(); $generator = $factory->getGenerator(new \SecurityLib\Strength(\SecurityLib\Strength::MEDIUM)); $string = $generator->generateString($length, $possibleChars); return $string; }
/** * {@inheritDoc} */ protected function execute(InputInterface $input, OutputInterface $output) { $factory = new \RandomLib\Factory(); $generator = $factory->getGenerator(new \SecurityLib\Strength(\SecurityLib\Strength::MEDIUM)); $pp = new PasswordPlease($generator); $password = $pp->generatePassword($input->getOption('length'), $input->getOption('complexity')); $output->writeln($password); }
public function test() { $factory = new RandomLib\Factory(); $generator = $factory->getGenerator(new SecurityLib\Strength(SecurityLib\Strength::MEDIUM)); // $generator = $factory->getLowStrengthGenerator(); $bytes = $generator->generate(32); var_dump($bytes); }
public function forgotPassword() { $userManager = new UserManager(); $succes = ""; $error = ""; if (!empty($_POST)) { $factory = new \RandomLib\Factory(); $generator = $factory->getGenerator(new \SecurityLib\Strength(\SecurityLib\Strength::MEDIUM)); $token = $generator->generateString(32, '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'); $email = $_POST['email']; // Verif si email existe dans la BDD if ($userManager->emailExists($email)) { $user = $userManager->getUserByUsernameOrEmail($email); $userManager->update(array("token" => $token), $user['id']); // Envois du mail $mail = new \PHPMailer(); $mail->isSMTP(); $mail->setLanguage('fr'); $mail->CharSet = 'UTF-8'; $mail->SMTPDebug = 2; //0 pour désactiver les infos de débug $mail->Debugoutput = 'html'; $mail->Host = 'smtp.gmail.com'; $mail->Port = 587; $mail->SMTPSecure = 'tls'; $mail->SMTPAuth = true; $mail->Username = "******"; $mail->Password = "******"; $mail->setFrom('ServiceMessagerie@BDloc', 'Service de Messagerie BDloc'); $mail->addAddress($email, $user['username']); $mail->isHTML(true); $mail->Subject = 'Envoyé par PHP !'; $app = getApp(); $router = $app->getRouter(); $url = $router->generate("resetMotdepasse", array("token" => $token)); $mail->Body = 'Nous avons bien reçu votre demande de renouvellement de mot de passe <br> pour changer votre mot de passe <a href="http://www.bdloc.dev' . $url . '">Cliquer ici</a>'; // SI email est bien envoyer if (!$mail->send()) { echo "Mailer Error: " . $mail->ErrorInfo; } else { echo "Message envoyé"; } $_SESSION['mail_succes'] = "Le mail a bien été envoyé !"; $this->redirectToRoute('oublieMotdepasse'); } else { $error = "Adresse Email non trouvé !"; } } $data = []; $data['succes'] = $succes; $data['error'] = $error; $this->show('user/forgotPassword', $data); }
private function generateApiKey() { $factory = new \RandomLib\Factory(); $generator = $factory->getGenerator(new \SecurityLib\Strength(\SecurityLib\Strength::MEDIUM)); $key = $generator->generateString(32, "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"); while (true) { $apiKey = ApiKeysModel::findFirst("key = '{$key}'"); if (!$apiKey) { break; } $key = $generator->generateString(32); } return $key; }
/** * 生成 cookie ,如果传入 selector 就 代表刷新 cookie 的token * 否则就是 生成一个全新的 cookie * @param string $selector * @return array */ private function _generate_cookie($selector = '') { $factory = new RandomLib\Factory(); $generator = $factory->getGenerator(new SecurityLib\Strength(SecurityLib\Strength::MEDIUM)); $token = $generator->generate($this->token_size); $token = hash('sha256', $token); if ($selector == '') { $selector = $generator->generateString($this->selector_size); } $cookie_value = $selector . $token; $this->_set_cookie($cookie_value); return array('selector' => $selector, 'token' => $token); }
$error = "Votre email n'est pas valide !"; } elseif (strlen($email) > 100) { $error = "Votre email est long !"; } //Si valide : email présent ? if ($error == "") { $sql = "SELECT * \n\t\t\t\tFROM users \n\t\t\t\tWHERE email = :email"; $sth = $dbh->prepare($sql); $sth->execute(array(":email" => $email)); $user = $sth->fetch(); } //SI on le trouve if ($user) { //token pour l'utilisateur $factory = new RandomLib\Factory(); $generator = $factory->getGenerator(new SecurityLib\Strength(SecurityLib\Strength::MEDIUM)); $token = $generator->generateString(80, '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_-'); $expiry = date("Y-m-d H:i:s", strtotime("+ 1 day")); $sql = "UPDATE users \n\t\t\t\t\t\tSET token = :token \n\t\t\t\t\t\ttoken_expery = :expiry \n\t\t\t\t\t\tdate_modified = NOW()\n\t\t\t\t\t\tWHERE id = :id"; $hashedToken = password_hash($token, PASSWORD_DEFAULT); $sth = $dbh->prepare($sql); $sth->bindValue(":token", $hashedToken); $sth->bindValue(":expiry", $expiry); $sth->bindValue(":id", $user['id']); if ($sth->execute()) { //on génère le lien complet $resetLink = ROOTURL . "/forgot_password_2.php?token={$token}&email={$email}"; //instance de PHPMailer $mail = getConfiguredMailer(); //qui envoie, et qui reçoit $mail->setFrom('*****@*****.**', 'Jeromewf3');
/** * Generates a random string of characters. * * @param int $amount * @param string $keyset * @return string * @static */ public static function keygen($amount, $keyset = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ123456789') { $amount = $amount >= 5 ? $amount : 5; $factory = new \RandomLib\Factory(); $generator = $factory->getGenerator(new \SecurityLib\Strength(\SecurityLib\Strength::MEDIUM)); $string = $generator->generateString($amount - 3, $keyset); $position = $generator->generateInt(0, $amount - 4); return substr($string, 0, $position) . $generator->generateString(1, 'ABCDEFGHIJKLMNOPQRSTUVWXYZ') . $generator->generateInt(0, 9) . $generator->generateString(1, 'abcdefghijklmnopqrstuvwxyz') . substr($string, $position); }
public function validate_email($uid, $email) { //生成 token $factory = new RandomLib\Factory(); $generator = $factory->getGenerator(new SecurityLib\Strength(SecurityLib\Strength::MEDIUM)); $token = md5(md5($generator->generate(128)) . time()); //发邮件 $this->send_email($email, $token); $this->email_model->insert_token($uid, $token); }
public function setUp() { $factory = new \RandomLib\Factory(); $this->generator = $factory->getGenerator(new \SecurityLib\Strength(\SecurityLib\Strength::MEDIUM)); $this->pp = new PasswordPlease($this->generator); }
/** * */ public function initProviders() { // Setup Swiftmailer, with optional SMTP settings. If no settings are provided in config.yml, mail() is used. $this->register(new \Silex\Provider\SwiftmailerServiceProvider()); if ($this['config']->get('general/mailoptions')) { $this['swiftmailer.options'] = $this['config']->get('general/mailoptions'); } // Set up our secure random generator. $factory = new \RandomLib\Factory(); $this['randomgenerator'] = $factory->getGenerator(new \SecurityLib\Strength(\SecurityLib\Strength::MEDIUM)); $this->register(new \Silex\Provider\UrlGeneratorServiceProvider()); $this->register(new \Silex\Provider\FormServiceProvider()); $this->register(new \Silex\Provider\ValidatorServiceProvider()); $this->register(new Provider\PermissionsServiceProvider()); $this->register(new Provider\StorageServiceProvider()); $this->register(new Provider\UsersServiceProvider()); $this->register(new Provider\CacheServiceProvider()); $this->register(new Provider\ExtensionServiceProvider()); $this->register(new Provider\StackServiceProvider()); $this['paths'] = getPaths($this['config']); $this['twig']->addGlobal('paths', $this['paths']); // Add the Bolt Twig functions, filters and tags. $this['twig']->addExtension(new TwigExtension($this)); $this['twig']->addTokenParser(new SetcontentTokenParser()); // Initialize enabled extensions. $this['extensions']->initialize(); // @todo: make a provider for the Integrity checker and Random generator.. // Set up the integrity checker for the Database, to periodically check if the Database // is up to date, and if needed: repair it. $this['integritychecker'] = new \Bolt\Database\IntegrityChecker($this); }