How to generate a random password in php | Coding Cluster - using asp.net, c#, mvc 4, iphone, php, ios, javascript, in asp.net mvc 3 & more
 

How to generate a random password in php

Wednesday

PHP: Generate a random password:
                            The followinf function will generate a random password. We just give total length of the password as input. For this we will print the function value, specifying the length of the password to be generated.

Code

<?php
<!--  -->
function generateRandomPassword($cnt)
{
// characters to be included for randomization, 
$chars= str_shuffle('abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890@#%$*');

// Here specify the 2nd parameter as start position, it can be anything, default 0
return substr($chars,0,$cnt);
}
// Usage 
$password = generateRandomPassword(7); // specify the length of the generated password
echo "Your random password is:".$password; 
<!-- --> ?>

1 comments:

Anonymous said...

Thanks for ur code...It helped me........

Post a Comment

Share your thoughts here...

 
 
 

RECENT POSTS

Boost

 
Blogger Widgets