Password Generator

De beste wachtwoorden zijn random gegenereerde wachtwoorden die bestaan uit hoofdletters, kleine letters, cijfers en vreemde tekens.

Om zelf een random aantal karaters achter elkaar te zetten is niet echt handig en vaak maak je het dan te makkelijk. Voor mezelf heb ik met PHP een klein scriptje gemaakt die dat voor mij kan doen.

Zelf hoef ik alleen nog maar de lengte van het wachtwoord te kiezen, op “Generate” te klikken en daarna nog even een keer op ” Copy”.
Standaard heb ik het script ingesteld dat ‘ie begint bij een lengte van 16 karakters. Dit is in de meeste gevallen al meer dan voldoende.

Voor wie deze reclame vrije Password Generator ook wil gebruiken:
https://rkoopmans.nl/start/passgen.php

<?php
/*
	Password Generator by Ronald Koopmans
	RKoopmans.nl
	2018-09-02 | 2019-04-19
	Version: 3.0

	This program is free software: you can redistribute it and/or modify
  it under the terms of the GNU General Public License as published by
  the Free Software Foundation, either version 3 of the License, or
  (at your option) any later version.

  This program is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  GNU General Public License for more details.

  You should have received a copy of the GNU General Public License
  along with this program.  If not, see <https://www.gnu.org/licenses/>
*/
$version = " Version: 3.0";
$copyright = "Copyright © 2018 - 2019 RKoopmans.nl";
$selectedBg = "matrix.jpeg"; //Choose a background of your own choice.

function randomPassword($length) {
	$alphabet = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890!@#$%&*()_-+=?,. '; // Add or Remove chars here
	$pass = array();
	$alphaLength = strlen($alphabet) - 1;
	for ($i = 0; $i < $length; $i++) {
		$n = rand(0, $alphaLength);
		$pass[] = $alphabet[$n];
	}
	return implode($pass);
};
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
	$length = $_POST['length'];
} else {
		$length = 16;
};
?>
<html>
	<head>
		<title>Password Generator</title>
		<style>
			body {
				background-image: url('<?php echo $selectedBg; ?>');
				height: 100%;
				background-position: center;
				background-size: cover;
				position: relative;
				color: white;
				font-family:Open Sans,Helvetica Neue,HelveticaNeue,TeXGyreHeros,Nimbus Sans L,Liberation Sans,Helvetica,Arial,sans-serif;
				font-size: 14px;
				overflow: hidden;
			}
			div {
				width: 100%;
			}
			.output {
				font-weight: normal;
				font-family: "Lucida Console", Monaco, monospace
				font-size: 100px;
			}
			.topleft {
				position: absolute;
				top: 0;
				left: 16px;
				font-size: 30px;
			}
			.bottomleft {
				position: absolute;
				bottom: 0;
				left: 16px;
			}
			.middle {
				position: absolute;
				top: 50%;
				left: 50%;
				transform: translate(-50%, -50%);
				text-align: center;
				font-size: 20pt;
			}
			hr {
				margin: auto;
				width: 40%;
			}
			.biggerform {
				font-size: 20pt;
			}
			.inputfield {
    		height: 100px;
				width: 100%;
    		font-size: 50pt;
				text-align: center;
			}
			.copybutton {
				font-size: 30pt;
			}
		</style>
	</head>
	<body align="center">
		<div>
  		<div class="topleft">
    		<h1>Password Generator</h1>
  		</div>
  		<div class="middle">
				<form method="post">
				<b>Length: </b>
					<select class="biggerform" name="length">
						<?php
							for ($o = 4; $o <= 1024; $o++) {
								if($o == $length) {
									$SEL = 'SELECTED';
								} else {
									$SEL = '';
								}
						?>
						<option value="<?php echo $o; ?>" <?php echo $SEL; ?>><?php echo $o; ?></option>
						<?php
						} ?>
					</select>
					<input  class="biggerform" type="submit" name="generate" value="Generate">
				</form>
				<p><input class="inputfield" type="text" class="output" value="<?php echo randomPassword($length); ?>" id="myInput"></p>
				<p><button class="copybutton" onclick="myFunction()">Copy</button></p>
    <p id="demo" style="font-size:75px"></p>
  </div>
  <div class="bottomleft">
    <p><?php echo $copyright; ?> | <?php echo $version; ?></p>
  </div>
</div>
<?php
?>
		<script>
			function myFunction() {
				var copyText = document.getElementById("myInput");
				copyText.select();
				document.execCommand("copy");
			}
		</script>
	</body>
</html>

Reacties zijn gesloten.