How password strength is measured
The strength of a randomly generated password is its entropy: the number of yes-or-no questions an attacker would have to answer to pin it down. It depends on two things only, the number of characters the generator could have picked from and the number of characters picked.
H = L × log2(N)
H is the entropy in bits, L is the length of the password and N is the size of the pool, meaning how many different characters each position could hold. The number of possible passwords is NL, which equals 2H. Each extra bit doubles the work for an attacker, and on average a password is found after half the possibilities have been tried.
Average guesses = 2(H − 1) and average time = average guesses ÷ guesses per second
The pool sizes used here are 26 uppercase letters, 26 lowercase letters, 10 digits and 32 symbols, the punctuation found on a standard keyboard. All four together give 94 characters.
Worked example: 16 characters from 94
- Pool size. 26 + 26 + 10 + 32 = 94.
- Bits per character. log2(94) = 6.5546.
- Entropy. 16 × 6.5546 = 104.87, or about 104.9 bits.
- Adjust for the “one from each set” rule. Insisting on at least one uppercase letter, lowercase letter, digit and symbol throws away the passwords that miss a set. About 82.3% of the possibilities remain, which costs 0.28 bits and leaves 104.59 bits. The calculator applies this correction whenever the rule is ticked.
How the password is generated
The characters come from crypto.getRandomValues, the browser’s cryptographically secure random source, not from the ordinary Math.random function, whose output can be predicted.
Turning a random number into a character needs care. The obvious method is to take the remainder after dividing by the pool size, but that favours some characters. A random byte has 256 values, and 256 = 2 × 94 + 68, so with a pool of 94 the first 68 characters would turn up three times in every 256 draws and the rest only twice. This page avoids the problem with rejection sampling: it draws a 32-bit number, and if the number falls in the small uneven remainder at the top of the range it is thrown away and drawn again. For a pool of 94 only 42 of the 4,294,967,296 possible values are rejected, and every character is then exactly equally likely.
The “at least one from each set” rule is applied the same way. A whole password is drawn, and if it lacks one of the chosen sets it is discarded and another is drawn. That keeps every acceptable password equally likely, which planting one character from each set in fixed positions would not.
Choosing the options
Length beats variety. Twenty lowercase letters carry 94.0 bits, more than a 12-character password using all 94 characters, which has 78.7 bits. If a site refuses symbols, add characters instead: each extra lowercase letter adds 4.70 bits.
Lookalike characters cost little. Leaving out I, l, 1, |, O and 0 shrinks the pool from 94 to 88. At 16 characters that is 103.35 bits instead of 104.87, a loss of 1.52 bits. It is worth it for any password that will be read aloud or typed from a screen.
Digits alone are weak for their length. A 16-digit number has only 53.15 bits, about the same as 8 characters drawn from all four sets (52.4 bits before the one-from-each rule).
Reading the time estimate. At the default assumption of 10 billion guesses a second, a 40-bit password lasts about 55 seconds on average, a 60-bit password about 1.8 years and an 80-bit password about 1.9 million years. The rate an attacker can really achieve depends on how the site stored the password: a slow, salted password hash cuts it by many orders of magnitude, and guessing against a live login page is slower still. Treat the figure as a comparison between options, not a prediction.
What entropy does not cover. The figure applies only to passwords produced at random. A password you invent, or a generated one you “improve” by hand, has less entropy than the formula says. Entropy also cannot protect a password that is reused on a site that is later breached, typed into a fake login page, or left in a clipboard history. Use a different password for every account, keep them in a password manager, and turn on multi-factor authentication where it is offered.