public function generate($amount, $params = array())
 {
     $this->params = array_merge($this->params, $params);
     $emailGenerator = new EmailGenerator();
     $passwordGenerator = new PasswordGenerator();
     $emails = $emailGenerator->generate($amount, $params);
     $params['unique'] = false;
     $passwords = $passwordGenerator->generate($amount, $params);
     for ($i = 0; $i < $amount; $i++) {
         $password = $passwords[$i];
         if ((bool) $this->params['hashed_password']) {
             // password should be hashed
             switch ($this->params['hash_function']) {
                 case 'sha1':
                     $password = sha1($password);
                     break;
                 case 'md5':
                 default:
                     $password = md5($password);
             }
         }
         $usercredential = str_replace('{email}', $emails[$i], $this->params['pattern']);
         $usercredential = str_replace('{password}', $password, $usercredential);
         $this->fake_data[] = $usercredential;
     }
     return $this->fake_data;
 }
 /**
  * Generate and update User with new password.
  * @param User $user
  * @return string
  */
 private function updateUserPassword(User $user)
 {
     $newPassword = PasswordGenerator::generate();
     $newPasswordHash = HashGenerator::generateMD5($newPassword);
     $user->setPassword($newPasswordHash);
     DAOFactory::getUserDAO()->save($user);
     return $newPassword;
 }
Exemple #3
0
function displayChecked($cond)
{
    if ($cond) {
        echo 'checked="checked"';
    }
}
function displaySelected($val1, $val2)
{
    if ($val1 === $val2) {
        echo 'selected="selected"';
    }
}
$password = '';
$pg = new PasswordGenerator($_POST);
if ($pg->isValid()) {
    $password = $pg->generate();
}
?>
<div class="container">
  <div class="row">
    <div class="center">
      <h1>Password Generator</h1>
    </div>
    <hr>
  </div>
  <div class="row">
    <div class="col-md-12 col-sm-12 col-xs-12">
      <div class="center">
        <h2 id="result"><?php 
echo $password;
?>
<?php

require 'password_generator.php';
$json = file_get_contents('php://input');
$options = json_decode($json, true);
$pg = new PasswordGenerator($options);
header('Content-Type: application/json');
if ($pg->isValid()) {
    http_response_code();
    echo json_encode($pg->generate());
} else {
    http_response_code(422);
    echo json_encode($pg->errors);
}
Exemple #5
0
require './resources/passgen.php';
define('__apiURL__', 'http://randomword.setgetgo.com/get.php');
$testAPI = function ($apiURL) {
    $api = new SimpleHttpGetRequest();
    $api->setURL($apiURL);
    return $api->get() && $api->getStatus() === 200;
};
$passGen;
$passWord;
$showApiError;
if ($testAPI(__apiURL__)) {
    $showApiError = false;
    $passGen = new PasswordGenerator($_GET);
    $passGen->setWordApiURL(__apiURL__);
    $passWord = $passGen->generate();
} else {
    $showApiError = true;
}
?>
<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <!-- The above 3 meta tags *must* come first in the head; any other head content must come *after* these tags -->
    <title>Project 2</title>
    <!-- Bootstrap 3.3.5 -->
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css">
    <link rel="stylesheet" href="css/style.css">