Wednesday, May 6, 2015

How to generate random password for user in php

function randomPasswordveer() {
    $alphabet = "abcdefghijklmnopqrstuwxyzABCDEFGHIJKLMNOPQRSTUWXYZ0123456789";
    $pass = array(); //remember to declare $pass as an array
    $alphaLength = strlen($alphabet) - 1; //put the length -1 in cache
    for ($i = 0; $i < 8; $i++) {
        $n = rand(0, $alphaLength);
        $pass[] = $alphabet[$n];
    }
    return implode($pass); //turn the array into a string
}


By this code program automatically generate password for uaser

How to use this code

<input type="hidden" name="user_pass" value="<?php echo randomPasswordveer();?>" >

Use it as your requirement in code

No comments:

Post a Comment

Dharamart.blogspot.in