PHP What is called this type of key? Like UUID

In the web application I'm working on, I need to create a unique identifier with excessive length. Longer than typical UUIDs. Another similar web application uses keys that look like this:

cb745abbc635c03f0c259b65y5da57c06e12ef51 

What are they called? and how can I create unique ones in PHP? I tried the UID method, however they are a bit short.

+5
source share
2 answers

The example you submitted is the sixth line of 40 characters, which therefore looks suspiciously like a SHA1 hash. The PHP built-in sha1() function will hash the input string in such a hash.

If you pass microtime(true) (to get the current time with microseconds as a float) as input, you will get a unique value in time. Combine it with the host name for a 40-digit globally unique value.

 echo sha1(microtime(true) . $hostname)); 

Note that although this type of value is probably satisfactory as a unique identifier for the database object, user identifier, etc., it should not be considered cryptographically secure, as its sequence can be easily guessed.

+2
source

This may be a hash derived from sha1, which is widely used:

From the PHP documentation :

If the raw_output option is set to TRUE, then instead of sha1 digest, a raw binary format of 20 is returned, otherwise the return value will be a hexadecimal number of 40 characters.

 echo (sha1("whatever")); 

Please note that this is not the case, as there are many other hashing algorithms that will give you a length of 40 characters:

 echo (hash("ripemd160", "whatever")); echo (hash("tiger160,3", "whatever")); echo (hash("tiger160,4", "whatever")); echo (hash("haval160,3", "whatever")); echo (hash("haval160,4", "whatever")); echo (hash("haval160,5", "whatever")); 
+1
source

Source: https://habr.com/ru/post/1203267/


All Articles