The code used for index.php is below:
<!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.0">
<link rel="stylesheet" href="../styles.css">
<title>Random Password Generator</title>
</head>
<body>
<?php
$error = '';
if(isset($_POST['generate'])){
$charset = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789%$#@!&()*-+^?><{}[]|";
$washed_chars = htmlentities($charset);
$password_length = htmlentities($_POST['password-length']);
$length_limit = 25;
if(!$password_length){
$err = "<h2>Password Length is Required</h2>";
$error = $err;
}
else if($password_length > $length_limit){
$err = "<h2>Password Must Be 25 Characters or Less</h2>";
$error = $err;
}
else {
$generated_password = substr(str_shuffle($washed_chars), 0, $password_length);
}
}
echo "<h1 class='lesson-h1'>Random Password Generator</h1>";
?>
<form action="index.php" method="post">
<textarea name="user-password" id="user-password" placeholder="Password Generates Here" cols="30">
<?php
if(isset($generated_password)){echo $generated_password;}
?>
</textarea>
<br>
<label for="password-range">Desired Password Length:
<br>
<input type="number" name="password-length" id="password-length" maxlength="2" placeholder="Choose: 1-25 Characters">
</label>
<br>
<input type="submit" value="Generate" name="generate">
</form>
<h3><?php echo $error; ?></h3>
<hr>
<?php
include('../show_code.php');
show_code('index.php');
?>
</body>
</html>