MiX1.TK
Site menu
Login form
Section categories
Web Development [20]
Learn about PHP & Web Development
Education [4]
Learn for Free
Knowledge & Tricks [0]
General Knowledge,computer Knowledge & tricks
Writing World [2]
A MiX World of SmS on Various Topics
Search
Main » 2012 » November » 6 » How to generate a random password
10:16 PM
How to generate a random password
<?php
class Randpass
{

function get_random_password($chars_min=6, $chars_max=8, $use_upper_case=false, $include_numbers=false, $include_special_chars=false)
    {
        $length = rand($chars_min, $chars_max);
        $selection = 'aeuoyibcdfghjklmnpqrstvwxz';
        if($include_numbers) {
            $selection .= "1234567890";
        }
        if($include_special_chars) {
            $selection .= "!@\"#$%&[]{}?|";
        }
                               
        $password = "";
        for($i=0; $i<$length; $i++) {
            $current_letter = $use_upper_case ? (rand(0,1) ? strtoupper($selection[(rand() % strlen($selection))]) : $selection[(rand() % strlen($selection))]) : $selection[(rand() % strlen($selection))];           
            $password .=  $current_letter;
        }               
       
        return $password;
    }
   
   
}   
    //call the function
    $obj = new Randpass();
    $getpassword=$obj->get_random_password(); //you can pass the parameters with overrite the values
    ?>
Category: Web Development | Views: 193 | Added by: admin-priyank | Rating: 5.0/1
Total comments: 0
Name *:
Email *:
Code *:
Calendar
«  November 2012  »
SuMoTuWeThFrSa
    123
45678910
11121314151617
18192021222324
252627282930
Entries archive
Our poll
Rate my site
Total of answers: 4
Site friends
  • Create a free website
  • Online Desktop
  • Free Online Games
  • Video Tutorials
  • All HTML Tags
  • Browser Kits
  • Statistics

    Total online: 1
    Guests: 1
    Users: 0
    Creative Commons License
    Free Downloads and Services by MiX1 is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License
    Copyright MyCorp © 2018