I am using codeigniter 3
And i am trying to build stay signing functionality
In hash_hmac() i am passing an array , but i want to convert it into a string ,
Can any one tell me how to convert it?

            | ---------------------------------------------------------------------------
            | REMEMBER ME TOKEN
            | ---------------------------------------------------------------------------
            | When a user logs in and selects the remember me option then you will generate a key using PHP's hash_hmac function. 
            | The data will be the IP address, browser name, username and password and the key (hash_hmac's 3rd parameter) 
            | will be a random string of any length you desire. 
            | The algorithm can be bcrypt/SHA512/crypt/etc.. This should give you a key of 128 characters in length. 
            | Store this key within the table RememberMe. 
            | Table contains user ID, 128 char long key ,expiry date of the key.      


                 if($remember_me == TRUE){


                    $user_agent = $this->agent->browser();
                    $user_agent_version = $this->agent->version();
                    $ip = $this->input->ip_address();

                    $rand128_hex = bin2hex(openssl_random_pseudo_bytes(16));

                    $data = array(
                            'ip' => $ip,
                            'user_agent' => $user_agent,
                            'email' => $email,
                            'password' => $password

                    echo hash_hmac('crypt', $data, $rand128_hex);


Edited by chaitu11

2 Years
Discussion Span
Last Post by diafol

Not quite sure what you're looking for - but I'm assuming it's to implode the array to a string:

$dataString = implode($data);
echo hash_hmac('crypt', $dataString, $rand128_hex);
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.