#native_company# #native_desc#
#native_cta#

Password Generator

By Michael
on April 29, 2004

Version: 4.0

Type: Function

Category: Algorithms

License: WebSite Only

Description: This function return Password consists of 0-9, a-z, A-Z

<?php
mt_srand((double) microtime() * 1000000);

function gen_random_password($password_length = 32, $generated_password = ""){
 $valid_characters = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
 $chars_length = strlen($valid_characters) - 1;
 for($i = $password_length; $i--; ) {
  $generated_password .= $valid_characters[mt_rand(0, $chars_length)];
 }
 return $generated_password;
}

?><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Password Generator v 4.0</title>
<style type="text/css">
body {
 font-family: Arial;
 font-size: 10pt;
}
</style>
</head>
<body>
<span style="font-weight: bold; font-size: 15pt;">Password Generator 4.0 by MJaC</span><br /><br />
<?php

if (isset($_GET['password_length'])){
 if(preg_match("/([0-9]{1,8})/", $_GET['password_length'])){
  print("Your password has been generated:<br />
<span style="font-weight: bold">" . gen_random_password($_GET['password_length']) . "</span><br /><br />n");
 } else {
  print("Invalid length for password!<br /><br />n");
 }
}

print <<< end
To generate a password, please specify the password's length:<br /><br />
<form action="{$_SERVER['PHP_SELF']}" method="get">
 <input type="text" name="password_length">
 <input type="submit" value="Create">
</form>
end;

?>
</body>
</html>