I am playing around with CSS/HTML/PHP and created a password generator:
<?php
$lowercase_characters = "abcdefghijklmnopqrstuvwxyz";
$uppercase_characters = strtoupper($lowercase_characters);
$numbers = "0123456789";
$symbols = ".-+=_,!@$#*%<>[]{}";
$chars = "";
$password ="";
function generatePassword($length, $chars){
$charsArray = str_split($chars);
for($i = 0; $i < $length; $i++){
shuffle($charsArray);
$password .= $charsArray[0];
}
echo '<div class="content-wrapper"><div class="result-content">Your generated password is:<br /><br /><input type="text" value="' . $password . '" onclick="select()" readonly="true"></div></div>';
}
if(isset($_POST['generate_password'])){
if(isset($_POST['symbols'])){
$chars .= $symbols;
}
if(isset($_POST['numbers'])){
$chars .= $numbers;
}
if(isset($_POST['lowercase_characters'])){
$chars .= $lowercase_characters;
}
if(isset($_POST['uppercase_characters'])){
$chars .= $uppercase_characters;
}
generatePassword(htmlspecialchars($_POST['p_length']), $chars);
}
?>
<div class="content-wrapper">
<div class="content">
<div class="content-header">
Password Generator
</div>
<form method="post">
<table class="index-table">
<tr>
<td width="30%">Password Lenght:</td>
<td width="70%"><input type="number" name="p_length" value="15" required /></td>
</tr>
<tr>
<td>Include Symbols:</td>
<td><input type="checkbox" name="symbols" checked /> (e.g. @#$%)</td>
</tr>
<tr>
<td>Include Numbers:</td>
<td><input type="checkbox" name="numbers" checked /> (e.g. 123456)</td>
</tr>
<tr>
<td>Include Lowercase Characters:</td>
<td><input type="checkbox" name="lowercase_characters" checked /> (e.g. abcdefg)</td>
</tr>
<tr>
<td>Include Uppercase Characters:</td>
<td><input type="checkbox" name="uppercase_characters" checked /> (e.g. ABCDEFG)</td>
</tr>
<tr>
<td></td>
<td><input type="submit" value="Generate Password" name="generate_password" class="generate-button" style="border: none;" /></td>
</tr>
</table>
</form>
</div>
</div>
It would be great if I could get some feedback on the code that I wrote, how to improve it and if there are any safety issues.