Showing posts with label Authentication String. Show all posts
Showing posts with label Authentication String. Show all posts

Wednesday, 31 August 2016

Generate an Authentication Code in PHP

In some email activation and verification processes we would need to make authentication codes for those verifications. This PHP function helps in generating such authentication codes for verification purpose. Make use of this code snippet for generating authentication codes.

function generateAuthenticationCode($length) {
    $ac = "abcdefghijklmnopqrstuvwxyz0123456789";
    $ac_len = strlen($ac);
    for($i=0; $i<$length; $i++){
        $position = rand(0,$ac_len);
        $authenticationCode .= $ac{$position};
    }
    return $authenticationCode;
}

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;
}