0

I want generate 5 digit number. the number will be used to verify phone numbers.

the random php functions doesn't use cryptographically strong algorithm, so I can't use them.

and openssl_random_pseudo_bytes generate also letters, I need just number .

How to do that ?

david
  • 3,310
  • 7
  • 36
  • 59
  • 1
    Use openssl_random_pseudo_bytes, convert that to hex, then convert the hex to an integer. – nneonneo May 07 '15 at 16:24
  • 1
    thank you for your answer, yes that's right, excuse me I have another question , does it safe to use openssl_random_pseudo_bytes to generate long tokens that used to verify user sessions. ? – david May 07 '15 at 16:32
  • 2
    Five digit numbers cannot be cryptographically secure, they are too short. There are only 99999 possible numbers, and that is small enough to crack by brute force. – rossum May 07 '15 at 21:17

0 Answers0