Automatic Intelligent Random Password Generator

Written by @m_k_amin 31 December 2012

It is something usual to produce a random password. It is used when a user has forgotten his password and need a new password; or in sum login register forms which the user can not choose his password at first. This script is an intelligent password generator. You set the number of letters and numbers used in the password phrase, and it randomly generates it. If you have a special name, number or character that must be in the phrase, you can insert it in the form. The script randomly select the place of numbers, letters and special phrases, too. Enjoy!

Code Snippet:

                                                
                                                <!-- this script is provided by https://www.phpfreecode.com coded by: Kerixa Inc. -->
<!-- This Script is from www.phpfreecpde.com, Coded by: Kerixa Inc-->
<?php
if (isset($_POST['Gen'])){
	$num=$_POST['num'];
	$let=$_POST['let'];
	$schar=$_POST['schar'];
	$sname=$_POST['sname'];
	$snum=$_POST['snum'];

	$l=strlen($sname)+strlen($snum)+strlen($schar)+$let+$num;
	$max=pow(10,$num)-1;
	$cnum=rand(1,$max);
	if (strlen($cnum)<$num) $cnum=$cnum*pow(10,$num-strlen($cnum));
	$clet='';
	for ($i=1;$i<=$let;$i++){
		$r=rand(1,2);
		if ($r==1) 
			$c=chr(rand(65,90));
		else
			$c=chr(rand(97,122));
		$clet.=$c;
	}
	$pass_a=array(0,$schar,$sname,$snum,$clet,$cnum);
	$pass_b[0]=0;
	for ($i=1;$i<=5;$i++){
		$used=true;
		while ($used==true){
			$n=rand(1,5);
			$used=false;
			for ($j=1;$j<=count($pass_b)-1;$j++)
				if ($n==$pass_b[$j]) $used=true;
		}
		$pass_b[]=$n;
	}
}
?>

<form action="" method="post" >
<table style="border: 1px solid #000000;width: 291px; height: 77px;" align="center">
	<tr>
		<td style="padding:5px; font-family: 'Times New Roman', Times, serif;font-size: 14pt; text-align: left; width: 1046px; color: #2214B9;border-style: solid;border-width: 1px; background-color: #FFFFE3; height: 38px;">
		Numbers Count:</td>
		<td style="border-style: solid;border-width: 1px; height: 39px;padding-left: 8px; width: 435px; padding-right: 5px; padding-top: 5px; padding-bottom: 5px; background-color: #FFFFE3;">
		<input name="num" style="font-family: 'Times New Roman', Times, serif; font-size: 14pt; width: 91px; text-align: center; color: #0AA24F;" value="<?php if (isset($_POST['Gen'])) echo $_POST['num'] ?>"></td>
		</tr>
	<tr>
		<td style="padding:5px; width: 1046px; border-style: solid;border-width: 1px;text-align: left; height: 39px; font-size: 14pt; background-color: #FFFFE3; font-family: 'Times New Roman', Times, serif;">
		<span style="color: #2214B9">Letters</span><span style="font-family: 'Times New Roman', Times, serif; color: #2214B9"> 
		Count:</span></td>
		<td style="border-style: solid;border-width: 1px; height: 39px;padding-left: 8px; width: 435px; padding-right: 5px; padding-top: 5px; padding-bottom: 5px; background-color: #FFFFE3;">
		<input name="let" style="font-family: 'Times New Roman', Times, serif; font-size: 14pt; width: 91px; text-align: center; color: #0AA24F;" value="<?php if (isset($_POST['Gen'])) echo $_POST['num'] ?>"></td>
	</tr>
	<tr>
		<td style="padding:5px; width: 1046px; border-style: solid;border-width: 1px;text-align: left; height: 39px; font-size: 14pt; background-color: #FFFFE3; font-family: 'Times New Roman', Times, serif; color: #2214B9;">
		Special Character:</td>
		<td style="border-style: solid;border-width: 1px; height: 39px;padding-left: 8px; width: 435px; padding-right: 5px; padding-top: 5px; padding-bottom: 5px; background-color: #FFFFE3;">
		<input name="schar" style="font-family: 'Times New Roman', Times, serif; font-size: 14pt; width: 91px; text-align: center; color: #0AA24F;" value="<?php if (isset($_POST['Gen'])) echo $_POST['schar'] ?>"></td>
	</tr>
	<tr>
		<td style="padding:5px; width: 1046px; border-style: solid;border-width: 1px;text-align: left; height: 39px; font-size: 14pt; background-color: #FFFFE3; font-family: 'Times New Roman', Times, serif; color: #2214B9;">
		Special Name:</td>
		<td style="border-style: solid;border-width: 1px; height: 39px;padding-left: 8px; width: 435px; padding-right: 5px; padding-top: 5px; padding-bottom: 5px; background-color: #FFFFE3;">
		<input name="sname" style="font-family: 'Times New Roman', Times, serif; font-size: 14pt; width: 91px; text-align: center; color: #0AA24F;" value="<?php if (isset($_POST['Gen'])) echo $_POST['sname'] ?>"></td>
	</tr>
	<tr>
		<td style="padding:5px; width: 1046px; border-style: solid;border-width: 1px;text-align: left; height: 39px; font-size: 14pt; background-color: #FFFFE3; font-family: 'Times New Roman', Times, serif; color: #2214B9;">
		Special Number:</td>
		<td style="border-style: solid;border-width: 1px; height: 39px;padding-left: 8px; width: 435px; padding-right: 5px; padding-top: 5px; padding-bottom: 5px; background-color: #FFFFE3;">
		<input name="snum" style="font-family: 'Times New Roman', Times, serif; font-size: 14pt; width: 91px; text-align: center; color: #0AA24F;" value="<?php if (isset($_POST['Gen'])) echo $_POST['snum'] ?>"></td>
	</tr>
	</table>
<p style="text-align: center">
		<input name="Gen" style="width: 148px; height: 64px; font-size: 25pt; font-family: 'Times New Roman', Times, serif; color: #119B23" type="submit" value="Generate"></p>
</form>
<?php if (isset($_POST['Gen'])){ ?>
	<table style="width: 301px" align="center">
		<tr>
			<td style=" padding:5px; background-color: #FABCAA; text-align: center; height: 64px;">
			<span style="font-family: 'Times New Roman', Times, serif; font-size: 16pt; color: #2214B9">
			Your Generated Password is:</span><br>
			<span style="font-size: 25pt; font-family: 'Times New Roman', Times, serif; color: #3FAC0F">
			<?php echo $pass_a[$pass_b[1]].$pass_a[$pass_b[2]].$pass_a[$pass_b[3]].$pass_a[$pass_b[4]].$pass_a[$pass_b[5]] ?>
			</span></td>
		</tr>
</table>
<?php } ?>
<div  style="text-align: center">
	<br>
	<font face="Tahoma">
	<span style="font-size: 8pt; text-decoration: none"><a target="_blank" href="http://www.phpfreecode.com/">
	PHP Free Code</a></span></font></div>
<a target='_blank' href='https://www.phpfreecode.com' style='font-size: 8pt; text-decoration: none'>Php Best Codes</a>                                                
                                            

Example:


About @m_k_amin

This user is pending a biography.

M

Comments


Here you can leave us commments. Let us know what you think about this code tutorial!

0 / 300

TRENDING POST
1
2
3
4
5
VISITORS
Online Users: 12
Recent Members: grkkid, Manaakividuinfo.com, karticksv, sava, tinatina
advertisement 2