Welcome Guest, Not a member yet? Register   Sign In
Suitabe tokens for autologin?
#2

This is how I do it there may be better ways not sure.

PHP Code:
    /**
     * guidV4 ()
     * ------------------------------------------------------------------------
     *
     * generates a GUID with 36 characters including hyphens
     *
     * Usage: $tmp = self::guidV4();
     * 
     *                           |-4  |- 8 9 a b
     * Format: XXXXXXXXXXXX-XXXX-xXXX-yXXX-XXXXXXXXXXXX
     *
     * @return string
     */
    
public static function guidV4()
    {
        
// this is for MS Windows Systems.
        
if (function_exists('com_create_guid') === true)
        {
            return 
trim(com_create_guid(), '{}');
        }

        
$data openssl_random_pseudo_bytes(16);

        
$data[6] = chr(ord($data[6]) & 0x0f 0x40); // set version to 0100
        
$data[8] = chr(ord($data[8]) & 0x3f 0x80); // set bits 6-7 to 10

        
return vsprintf('%s%s-%s-%s-%s-%s%s%s'str_split(bin2hex($data), 4));
    }

    
/**
     * generateToken ()
     * --------------------------------------------------------------------
     *
     * Generates an array with selector | validator then it will hash them
     *
     * USAGE: generateToken();
     * 
     * @return  array
     */
    
private function generateToken()
    {
        
/**
         * If you define a namespace, you can prefix it to the GUID
         * Just un-remark the line below and rem the other line.
         */

        //$tmp = Uuid_Namespace."-".self::guid_v4();
        
$tmp  self::guidV4();

        
$tokenData = array(
            
'selector' => $tmp,
            
'token'    => base64_encode(hash('sha256'$tmp)),
        );

        return 
$tokenData;
    } 
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply


Messages In This Thread
Suitabe tokens for autologin? - by wolfgang1983 - 07-27-2016, 01:21 AM
RE: Suitabe tokens for autologin? - by InsiteFX - 07-27-2016, 03:31 AM
RE: Suitabe tokens for autologin? - by CallHimX - 07-27-2016, 03:47 AM



Theme © iAndrew 2016 - Forum software by © MyBB