Create Ramdom Password For Your User In Php

Some time when you need to generate ramdom password or something like random string.Then my this code is really helpful for you.

function createRandomPassword() {
        $chars = "abcdefghijkmnopqrstuvwxyz023456789";
        srand((double)microtime()*1000000);
        $i = 0;
        $pass = '' ;
        while ($i <= 7) {
            $num = rand() % 33;
            $tmp = substr($chars, $num, 1);
            $pass = $pass . $tmp;
            $i++;
        }
        return $pass;
    }


This is my function which will generate 7 digit random password and return you every time when it call.If you want to increase the number of digit of password then change the loop limit  here.. {while ($i <= 7)}.


Regards
Salman Ahmad


Happy Coding :)

Post a Comment

Previous Post Next Post