How to generate password from given length and character set in php?


function generatePassword($length,$chars) {

    $count = mb_strlen($chars);

    for ($i = 0, $result = ”; $i < $length; $i++) {
        $index = rand(0, $count – 1);
        $result .= mb_substr($chars, $index, 1);
    }
    //echo $result;

    return $result;
}
$var=  generatePassword(5,’laitkor1234′);
echo $var;

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s