Generate token from string and check generated token

2

Basically, I need something that works similar to $hash = Hash::make('string') and Hash::check('string', $hash) but does not produce a result as large as (60 characters).

  

or $hash = password_hash('string') and password_verify('string', $hash) with pure PHP

How to generate a token from a string and then check if the generated token matches the generating string?

    
asked by anonymous 14.08.2015 / 19:08

1 answer

3

Have you tried using md5 ? It will generate a string of 32 characters

See:

echo md5('joãozinho'); // 'a7199fb05606b0d193d79a2dd6c2b537'

For verification:

 $codigo = 'a7199fb05606b0d193d79a2dd6c2b537';

 var_dump(md5('joãozinho') == $codigo); // True

I do not know if this is a good idea, but I've seen lots of people using md5 with a substr to reduce that number of characters from md5 .

  substr(md5('joãozinho'), 0, 8); //Imprime: 'a7199fb0'
    
14.08.2015 / 22:23