Generate token from string and check generated token

Asked

Viewed 6,661 times

2

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

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

To generate a "token" from a string and then check whether the generated "token" corresponds to the generating string?

  • 1

    Why don’t you want a 60-character hash? It’s much safer than md5, each run generates a different hash, is efficient and testable. 60 characters does not affect performance.

1 answer

4


Have you tried using md5? It will generate a 32-character string

Behold:

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

For verification:

 $codigo = 'a7199fb05606b0d193d79a2dd6c2b537';

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

I don’t know if this is a good idea, but I’ve seen a lot of people using the md5 with a substr to reduce this number of characters in the md5.

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

Browser other questions tagged

You are not signed in. Login or sign up in order to post.