The same engine, minus the login-form rules
This is the password generator with the constraints removed. No requirement that every character class appears, because no API validates a token that way, and no assumption you are going to type it by hand. What is left is the thing a developer actually wants: an arbitrary number of uniformly random characters from a pool you choose.
Everything else is identical. The characters come from crypto.getRandomValues, values that would introduce a bias towards certain characters are discarded and redrawn, and nothing leaves the page.
How long is long enough
The usual target for a secret is 128 bits of entropy, which is the point at which guessing is no longer anybody’s route in. What that means in characters depends on the pool:
| Pool | Size | Bits per character | Characters for 128 bits |
|---|---|---|---|
| Digits only | 10 | 3.32 | 39 |
| Lowercase only | 26 | 4.70 | 28 |
| Letters and digits | 62 | 5.95 | 22 |
| Everything | 86 | 6.43 | 20 |
The gap between the safest and the most convenient pool is two characters. That is the whole argument for leaving symbols out of anything that will pass through a shell, a URL or a config file.
What these are good for
- API keys and bearer tokens — 32 characters of letters and digits is a sensible default.
- Salts — though a hashing library will usually generate its own, and should be allowed to.
- Session identifiers — as long as they are treated as secrets and not logged.
- Test and seed data — where you want values that look real and collide with nothing.
What they are not good for
Anything that has to survive being read aloud, retyped or transcribed. A 32-character random string is hostile to human hands, which is exactly right for a machine credential and exactly wrong for a login someone has to type. For that, use the passphrase generator.
These are also not a substitute for a key derivation function. If you are turning a password into an encryption key, use a proper KDF such as Argon2 or scrypt rather than a random string, and let the library handle the salt.