Password Generator: how it works and how to build one
Strong random passwords and passphrases. This guide explains what happens behind the button and shows the code, so you can build your own.
What it does
Uses your browser’s cryptographic random generator. Choose the length and character sets, avoid look-alike characters, and see the strength in bits of entropy.
When to use it
- New accounts
- Wi-Fi passwords
- API secrets
How to use it
- Set the length and character types.
- Click Generate for a new one.
- Copy it into your password manager.
Try it free in your browser, nothing is uploaded: https://eskillsfy.com/tools/password-generator
How it works
Strong passwords come from a cryptographically secure random source: crypto.getRandomValues, never Math.random. To pick a character without bias, the generator throws away random numbers above the largest multiple of the pool size (rejection sampling).
Strength is measured as entropy: length × log2(pool size). 20 characters from 80 symbols is about 126 bits, far beyond guessing.
Build it yourself
Here is the core of the tool. It has no dependencies unless noted, so you can paste it into any TypeScript or JavaScript project.
password.ts (ts)
function randomInt(max: number) {
const limit = 2 ** 32 - (2 ** 32 % max);
let x: number;
do x = crypto.getRandomValues(new Uint32Array(1))[0]; while (x >= limit); // no modulo bias
return x % max;
}
export function password(length = 20, pool = "abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ23456789!@#$%^&*") {
return Array.from({ length }, () => pool[randomInt(pool.length)]).join("");
}
export const entropyBits = (length: number, poolSize: number) => Math.round(length * Math.log2(poolSize));
Make it production-ready
- Guarantee at least one of each chosen character type.
- Add passphrases from a word list (easier to type).
Questions
Is the password stored anywhere?
No. It is generated in your browser and is gone when you leave the page.
How long should it be?
16 characters with mixed types is above 100 bits of entropy, which is plenty for most accounts.
Free, runs in your browser, nothing is uploaded.