Random Password Generator – closingtags </>

Random Password Generator

I’ve had a little bit of downtime at work, and didn’t want to be idle. Luckily for me, I found this awesome subreddit, called /r/dailyprogrammer. They’ve got tons of programming challenges for a wide variety of skills. So I’ve been picking through some simple ones in my down time, and doing some of the easier ones. This one is the most recent challenge I did.

Basically, it just asks you to create a random password generator (like this one) with the ability to specify how many passwords to generate, and how long the string should be. And since the comments are closed, I can’t really submit my solution there, so here is what I came up with, in PHP.

<!DOCTYPE html>
	<div style="text-align: center; margin: 50px;">
		<form action="passwords.php" method="post" style="margin-bottom: 25px;" enctype="multipart/form-data">
			<label for="inputs"># of passwords: </label>
			<input type="text" name="text1" id="text1"><br><br>
			<label for="inputs">string length: </label>
			<input type="text" name="text2" id="text2"><br><br>
			<input type="submit" name="submit" value="Submit">
			if($_POST["text1"] && $_POST["text2"]) {
				$max = intval($_POST["text1"]);
				$length = intval($_POST["text2"]);
				$count = 0;

				$seed = str_split("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!@#$%^&*()_", 1);
				$tehstring = "";

				while($count < $max) {
					for ($i=0; $i < $length; $i++) {
						$tehstring .= $seed[mt_rand(0, count($seed)-1)];
					echo $tehstring . "<br>";
					$tehstring ="";


By Dylan Hildenbrand

Full stack web developer experienced with #PHP, #SvelteKit, #JS, #NodeJS, #Linux, and #Ansible. I love a good challenge.

profile for Dylan Hildenbrand on Stack Exchange, a network of free, community-driven Q&A sites  

Do you like these posts? Consider sponsoring me or making a donation!

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.