A
A
Artem2016-01-05 19:14:52
PHP
Artem, 2016-01-05 19:14:52

How to generate a cryptographically secure token for an API?

For authorization in the API, it is necessary to generate unique tokens. What is the best way to do this so that they are truly unique and protected?
I found this function in the manual :

string openssl_random_pseudo_bytes ( int $length [, bool &$crypto_strong ] )

Can it be used for such purposes? I didn't quite understand about the second parameter:
If passed into the function, this will hold a boolean value that determines if the algorithm used was "cryptographically strong", eg, safe for usage with GPG, passwords, etc. TRUE if it did, otherwise FALSE

that is, you need to call this function until the second parameter becomes true ? And before that, can it be false a million times?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question