Free

Password Generator

Math.random() must never make a password — and avoiding modulo bias is the part most people get wrong.

  • JavaScript
  • Web Crypto
  • CSS
  • HTML

About this project

A password generator with a length slider, character-set toggles, a look-alike filter, copy to clipboard, and a strength meter that reports entropy in bits with the actual number on it instead of the word "strong".

There are two separate mistakes it exists to teach, both in one small function. The first is the source: Math.random() is only required to be approximately uniform, is produced by an algorithm with a fixed amount of state, and can be recomputed by anyone who recovers that state. A password from Math.random() is not something an attacker has to guess. The second is the mapping: taking a random byte and reducing it with the modulo operator makes some characters more likely than others, and the page includes a live experiment that demonstrates the skew rather than asking you to take it on trust.

The app takes its own argument seriously. If crypto.getRandomValues is missing it disables every control and refuses to generate, because a fallback would produce a password that looks identical on the meter and is not.

What you will learn

  • Know why Math.random() is unsuitable for secrets, and what makes crypto.getRandomValues() different
  • Implement rejection sampling, and understand the modulo bias it removes
  • Calculate password strength as entropy in bits rather than guessing at a label
  • Measure the real cost of common password rules, like "at least one of each type"
  • Refuse to degrade: fail loudly when the secure source is missing rather than falling back

Before you start

  • JavaScript basics — arrays, functions and events
  • Comfort with logarithms helps for the entropy section, but the README derives it
  • A browser and a text editor. Nothing to install.

New to JavaScript? The free JavaScript course covers everything this project assumes.

Academic integrity notice

These projects are provided for learning, experimentation and reference. Understand the code, modify it for your own requirements, and acknowledge external work according to your institution’s academic policies. Priodemy does not supply work to be submitted as your own.