<html>
<head>
</head>
<body>
<?php
function generateRandomString($length = 10) {
$characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
$charactersLength = strlen($characters);
$randomString = '';
for ($i = 0; $i < $length; $i++) {
$randomString .= $characters[rand(0, $charactersLength - 1)];
}
return $randomString;
}
?>
<form method="post" action="<?php echo $_SERVER['PHP_SELF']?>">
<center>
<?php if(isset($_POST['genBtn'])){?><h1>Generated password is </h1>
<h2><?php if(isset($_POST['length'])){echo generateRandomString($_POST['length']);} else {echo generateRandomString(12);}?></h2>
<?php }?> <label>Enter the required password length</label>
<input type="text" name="length" value="<?php if(isset($_POST['length'])){echo trim($_POST['length']);} else {echo 10;}?>" >
<input type="submit" name="genBtn" value="Generate Password">
</center>
</form>
</body>
</html>
<head>
</head>
<body>
<?php
function generateRandomString($length = 10) {
$characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
$charactersLength = strlen($characters);
$randomString = '';
for ($i = 0; $i < $length; $i++) {
$randomString .= $characters[rand(0, $charactersLength - 1)];
}
return $randomString;
}
?>
<form method="post" action="<?php echo $_SERVER['PHP_SELF']?>">
<center>
<?php if(isset($_POST['genBtn'])){?><h1>Generated password is </h1>
<h2><?php if(isset($_POST['length'])){echo generateRandomString($_POST['length']);} else {echo generateRandomString(12);}?></h2>
<?php }?> <label>Enter the required password length</label>
<input type="text" name="length" value="<?php if(isset($_POST['length'])){echo trim($_POST['length']);} else {echo 10;}?>" >
<input type="submit" name="genBtn" value="Generate Password">
</center>
</form>
</body>
</html>
0 comments:
Post a Comment