Tuesday 19 July 2016

PHP Function generate authentication string

Simple PHP function to generate a authentication string. Create a random string in php. Generate random password in php using a simple function.

function generateAuthenticationString($length) {
    $allowedChars = "abcdefghijklmnopqrstuvwxyz0123456789";
    $string = "";
    for($i=0;$i<$length;$i++){
        $randPos = rand(0,36);
        $string .= $allowedChars{$randPos};
    }
    return $string;
}

No comments:

Post a Comment