a RNG that isn't considered cryptographically secure.a smaller character space than you wanted so that either brute-forcing is easier or the password must be longer for the same entropy.I'm going to post an answer because some of the existing answers are close but have one of: Throw new Exception('$keyspace must be at least two characters long') $keyspace = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ' * string $keyspace A string of all possible characters * int $length How many characters do we want? * For PHP 7, random_int is a PHP core function * pseudorandom number generator (random_int) * Generate a random string, using a cryptographically secure With a secure random integer generator on hand, generating a secure random string is easier than pie:
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |