this function allow you to generate random characters code,function suitable for
Generate activation code for newly user account
Generate shortenURL code,
Generate temporary user password for changing password of account.
function generate_special_pass($pass_len = 8, $allow_special_chrs = true) {
$allow_chrs = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz';
$special_chrs = '!@#$%^&*()_+';
if($allow_special_chrs) {
$pass_chrs = $allow_chrs.$special_chrs;
} else {
$pass_chrs = $allow_chrs;
}
$pass_rand_val = null;
for($inc =1;$inc<=$pass_len; $inc++ ) {
$rand_pos = rand(0,strlen($pass_chrs)-1);
$pass_rand_val .= substr($pass_chrs ,$rand_pos , 1);
}
return $pass_rand_val;
}
The 10 is characters limits its generate password with 10 characters and true allow to add special characters these define in $special_vars variable.
echo generate_special_pass(10, true)
//RESULT=Af$@tHiO*q
Now call it as non-special characters with limit of 20
echo generate_special_pass(20, false)
//RESULT=gHoQ0vM5lbX9i1Z70D4B
Currently working in software house named Wiztech as position of Senior Web Developer, I love to share tips and techniques of programming, author of SDTuts 27 years old, I am from Karachi, Sindh, Pakistan and I am working on Web Designing and Development with Adobe Photoshop CS, HTML, CSS, JavaScript,…Read More Description