Skip to main content

Generate Random password

<?php
/*
This class creates random password with alphanumeric values, and its md5 value can be stored in database. Generally useful in cases like when a user forgets his password.
*/

class PassMd5
{
private $password;

public function create($pass)
{
$str = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890';

$pass = '';

for($i=0;$i<12;$i++)
{
$pass .= substr($str,rand(0,62),1);
}

$this->password=$pass;
return $this->password;
}

} // end of class

// example of how to use

$newpass=new PassMd5();
echo "New password = ".$newpass->create($pass);
echo "<br>(md5) of New password = ".md5($newpass->create($pass));
?>

Output:

Comments

Popular posts from this blog

Retaining checkbox status of a form after submitting it

we will learn here how to post back or retain the value ( status ) of the checkbox. We will use php header redirection to post back the values to our main page where checkbox is present. We will call form page as first page and action or submitted page as second page. The form data will be received by second page and it is supposed to post back the form data back to form page by using query string through address bar. To keep the second page simple we will keep only the redirection part. Here we have excluded the part which takes care if the form passes its validation and execute the actual script (redirection part). Here is the code of our form with two checkboxes, pb-check.php <?php $t1=$_GET['t1']; $t2=$_GET['t2']; if($t1=="yes"){$t1v="checked";} else{$t1v=="";} if($t2=="yes"){$t2v="checked";} else{$t2v=="";} ?> HTML Form code: <form method="post" action="pb-chk.php"> <inp...

Joomla validate chrono forms using jquery

It is a common practice to use Chrono forms in our joomla site to setup various forms in the site, be it a contact us form, submit a ticket form, or whatever. I have set the option "validate form" to "No" under chronoform settings in admin panel, and also preferred to not include any js or css files. For validating the chrono forms, i prefer jquery. So first lets add jquery support in our joomla. It is quite simple: 1. Download jquery.js and jquery_min.js (1.4.2 version is enough) and place them in media/system/js folder of your joomla. 2. Edit libraries->joomla->html->html->behavior.php, and add the following function below the mootools() function: function jQuery($debug = null)     {         static $loaded;         global $mainframe;         // Only load once         if ($loaded) {    ...

check file type in upload

Script code: <script type="text/javascript">function check_upload(upload_field){    var re_text = /\.txt|\.pdf|\.zip/i;    var filename = upload_field.value; /* Checking file type */    if (filename.search(re_text) == -1)    {        alert("File does not have (txt / pdf / zip) extension");        upload_field.form.reset();        return false;    }return true; } function verify_upload(){ if(document.upload_file.file1.value == "") { alert("Please select a file"); return false; }return true; }</script> Form code: <form name="upload_file" action="" method="post" enctype="multipart/form-data"><input type="file" name="file1" id="file" onChange="check_upload(this)"><input type="submit" name="submit" value="Upload" onclick="return verify_upload()" /></form>