public function generatePassword(Request $request) { $data = 'POST' === $request->getMethod() ? $this->handleRequest($request) : $request->query->all(); $generator = new \PWGen(); $generator->setCapitalize((bool) $data['upper_case'])->setNumerals((bool) $data['numbers'])->setSecure((bool) $data['secure'])->setSymbols((bool) $data['symbols'])->setLength((int) $data['length']); return new JsonResponse(['password' => $generator->generate()], 200); }
/** * @param \ArrayObject $project * * @return mixed */ public function create(\ArrayObject $project) { $project["dbuser"] = $this->dialogProvider->askFor("Enter a PostgreSQL username", null, $project["name"]); $pwgen = new \PWGen(); $project["dbpass"] = $this->dialogProvider->askFor("Enter a PostgreSQL password", null, $pwgen->generate()); $project["dbname"] = $this->dialogProvider->askFor("Enter a PostgreSQL databasename", null, $project["name"]); $project["dbserver"] = $this->dialogProvider->askFor("Enter a PostgreSQL server host", null, "localhost"); }
public static function generate($intLength = 8, $blnPreventAmbiguous = true, $arrAlphabets = null, $arrRules = null, $strAllowedSpecialChars = null) { $arrAlphabets = is_array($arrAlphabets) ? $arrAlphabets : static::$arrAlphabets; $arrRules = is_array($arrRules) ? $arrRules : static::$arrRules; $strAllowedSpecialChars = $strAllowedSpecialChars !== null ? $strAllowedSpecialChars : static::$strAllowedSpecialChars; $pwGen = new \PWGen($intLength, false, in_array(CodeGenerator::NUMBERS, $arrAlphabets) && in_array(CodeGenerator::NUMBERS, $arrRules), in_array(CodeGenerator::CAPITAL_LETTERS, $arrAlphabets) && in_array(CodeGenerator::CAPITAL_LETTERS, $arrRules), $blnPreventAmbiguous, false, in_array(CodeGenerator::SPECIAL_CHARS, $arrAlphabets) && in_array(CodeGenerator::SPECIAL_CHARS, $arrRules)); $strCode = $pwGen->generate(); // replace remaining ambiguous characters if ($blnPreventAmbiguous) { $arrCharReplacements = array('y', 'Y', 'z', 'Z', 'o', 'O', 'i', 'I', 'l'); foreach ($arrCharReplacements as $strChar) { $strCode = str_replace($strChar, StringUtil::randomChar(!$blnPreventAmbiguous), $strCode); } } // apply allowed alphabets $strForbiddenPattern = ''; $strAllowedChars = ''; if (!in_array(CodeGenerator::CAPITAL_LETTERS, $arrAlphabets)) { $strForbiddenPattern .= 'A-Z'; } else { $strAllowedChars .= $blnPreventAmbiguous ? StringUtil::CAPITAL_LETTERS_NONAMBIGUOUS : StringUtil::CAPITAL_LETTERS; } if (!in_array(CodeGenerator::SMALL_LETTERS, $arrAlphabets)) { $strForbiddenPattern .= 'a-z'; } else { $strAllowedChars .= $blnPreventAmbiguous ? StringUtil::SMALL_LETTERS_NONAMBIGUOUS : StringUtil::SMALL_LETTERS; } if (!in_array(CodeGenerator::NUMBERS, $arrAlphabets)) { $strForbiddenPattern .= '0-9'; } else { $strAllowedChars .= $blnPreventAmbiguous ? StringUtil::NUMBERS_NONAMBIGUOUS : StringUtil::NUMBERS; } if ($strForbiddenPattern) { $strCode = preg_replace_callback('@[' . $strForbiddenPattern . ']{1}@', function () use($strAllowedChars) { return StringUtil::random($strAllowedChars); }, $strCode); } // special chars if (!in_array(CodeGenerator::SPECIAL_CHARS, $arrAlphabets)) { $strCode = preg_replace_callback('@[^' . $strAllowedChars . ']{1}@', function () use($strAllowedChars) { return StringUtil::random($strAllowedChars); }, $strCode); } else { $strCode = preg_replace_callback('@[^' . $strAllowedChars . ']{1}@', function () use($strAllowedSpecialChars) { return StringUtil::random($strAllowedSpecialChars); }, $strCode); } return $strCode; }
//Send to user his new pw if key is conform //Send to user his new pw if key is conform case "generate_new_password": //check if key is okay $data = $db->fetch_row("SELECT valeur FROM " . $pre . "misc WHERE intitule = '" . $_POST['login'] . "' AND type = 'password_recovery'"); if ($_POST['key'] == $data[0]) { //Generate and change pw $new_pw = ""; include '../includes/libraries/pwgen/pwgen.class.php'; $pwgen = new PWGen(); $pwgen->setLength(10); $pwgen->setSecure(true); $pwgen->setSymbols(false); $pwgen->setCapitalize(true); $pwgen->setNumerals(true); $new_pw_not_crypted = $pwgen->generate(); $new_pw = encrypt(string_utf8_decode($new_pw_not_crypted)); //update DB $db->query_update("users", array('pw' => $new_pw), "login = '******'login'] . "'"); //Delete recovery in DB $db->query_delete("misc", array('type' => 'password_recovery', 'intitule' => $_POST['login'], 'valeur' => $key)); //Get email $data_user = $db->query_first("SELECT email FROM " . $pre . "users WHERE login = '******'login'] . "'"); $_SESSION['validite_pw'] = false; //load library require_once "../includes/libraries/phpmailer/class.phpmailer.php"; //send to user $mail = new PHPMailer(); $mail->SetLanguage("en", "../includes/libraries/phpmailer/language/"); $mail->IsSMTP(); // send via SMTP
/** * A wrapper for PWGen */ public static function generatePassword($random = true) { $pwgen = new \PWGen(); return $pwgen->generate(); }
// Include at least one number in the password $pwgen->setNumerals($_POST['num'] == "true" ? true : false); // Include at least one capital letter in the password $pwgen->setCapitalize($_POST['maj'] == "true" ? true : false); // Include at least one symbol in the password $pwgen->setSymbols($_POST['symb'] == "true" ? true : false); // Complete random, hard to memorize password if (isset($_POST['secure']) && $_POST['secure'] == "true") { $pwgen->setSecure(true); $pwgen->setSymbols(true); $pwgen->setCapitalize(true); $pwgen->setNumerals(true); } else { $pwgen->setSecure(false); } echo json_encode(array("key" => $pwgen->generate()), JSON_HEX_TAG | JSON_HEX_APOS | JSON_HEX_QUOT | JSON_HEX_AMP); break; /* * CASE * Delete an item */ /* * CASE * Delete an item */ case "del_item": //delete item consists in disabling it $db->query_update("items", array('inactif' => '1'), "id = " . $_POST['id']); //log $db->query_insert("log_items", array('id_item' => $_POST['id'], 'date' => mktime(date('H'), date('i'), date('s'), date('m'), date('d'), date('y')), 'id_user' => $_SESSION['user_id'], 'action' => 'at_delete')); //Update CACHE table
$pwgen->setNumerals($_POST['num'] == "true" ? true : false); // Include at least one capital letter in the password $pwgen->setCapitalize($_POST['maj'] == "true" ? true : false); // Include at least one symbol in the password $pwgen->setSymbols($_POST['symb'] == "true" ? true : false); // Complete random, hard to memorize password if ($_POST['secure'] == "true") { $pwgen->setSecure(true); $pwgen->setSymbols(true); $pwgen->setCapitalize(true); $pwgen->setNumerals(true); } else { $pwgen->setSecure(false); } // Generate KEY $key = $pwgen->generate(); if (isset($_POST['fixed_elem']) && $_POST['fixed_elem'] == 1) { $myElem = $_POST['elem']; } else { $myElem = $_POST['elem'] . 'pw1'; } echo 'document.getElementById(\'' . $myElem . '\').value = "' . addslashes($key) . '";'; if (!isset($_POST['fixed_elem'])) { echo 'runPassword(document.getElementById(\'' . $myElem . '\').value, \'' . $_POST['elem'] . 'mypassword\');'; } echo '$("#' . $_POST['elem'] . 'pw_wait").hide();'; break; ############# ### CASE #### ### Delete an item #############
<tr><td align="right"><b>Hostname:</b></td><td><input type="text" name="host" size="30" maxlength="30" value="<?php if (isset($host)) { echo $host; } ?> "> *</td></tr> <tr><td align="right"><b>IP:</b></td><td><input type="text" name="ip" onBlur="isIP(this)" size="30" maxlength="30" value="<?php if (isset($ip)) { echo $ip; } ?> "> *</td></tr> <?php include 'pwgen.class.php'; $pwgen = new PWGen(); $password = $pwgen->generate(); ?> <tr><td align="right"><b>Usuário:</b></td><td><input type="text" name="user" size="15" maxlength="60" value="<?php if (isset($user)) { echo $user; } ?> "> *</td></tr> <tr><td align="right"><b>Senha:</b></td><td><input type="password" name="password" size="15" maxlength="30"> *</td><td align="left"><b>Sugestão de senha:</b> <font color="red" size="4"><?php if (isset($password)) { echo $password; } ?> </font> </td></tr>
/** * Generate password provides a generated password * * * @return password (plaintext) */ public function generate_password() { include CMFPATH . "vendor/passgen/pwgen.class.php"; $pwgen = new \PWGen(); $password = $pwgen->generate(); return $password; }
//Encrypt the file if (!empty($_POST['option'])) { $return = encrypt($return, $_POST['option']); } //write file fwrite($handle, $return); fclose($handle); //generate 2d key include '../includes/libraries/pwgen/pwgen.class.php'; $pwgen = new PWGen(); $pwgen->setLength(20); $pwgen->setSecure(true); $pwgen->setSymbols(false); $pwgen->setCapitalize(true); $pwgen->setNumerals(true); $_SESSION['key_tmp'] = $pwgen->generate(); echo '[{"result":"db_backup" , "href":"sources/downloadFile.php?name=' . urlencode($filename) . '&path=' . $path . $filename . '&type=sql&key=' . $_SESSION['key'] . '&key_tmp=' . $_SESSION['key_tmp'] . '"}]'; } break; ########################################################### #CASE for restoring a DB backup ########################################################### #CASE for restoring a DB backup case "admin_action_db_restore": require_once 'main.functions.php'; $data_post = explode('&', $_POST['option']); $file = $data_post[0]; $key = $data_post[1]; //create uncrypted file if (!empty($key)) { //read full file