Skip to content
Tutorials Center
My learning

Topics

Lesson 66 of 71 ยท Projects

Project: Password Manager and Password Validator

Build a password strength validator, a secure password generator and a small password manager in React Native, with SecureStore, masking, biometrics and clipboard rules.

Passwords are a perfect project because they force you to make security decisions, not just draw screens: where may a secret be stored, when may it be shown, what must never be logged. You will build three connected pieces: a validator that scores a password, a generator that makes strong ones, and a manager that keeps a list of saved logins. The logic is pure JavaScript you can run and test; the storage and device parts are read-only React Native code with the reasoning behind each choice.

This is a learning project. A real password manager needs a reviewed encryption design, a recovery story and security audits. For a production product, use the platform's own credential features (Passkeys, iCloud Keychain, Android Credential Manager) or a proven library, and never invent your own cryptography.

What runs on this site. SecureStore, biometrics and the clipboard are native, so their code is read-only. The validator, generator and vault logic run below with stand-in screens.

Part 1: the password validator

What makes a password strong

Older rules ("one capital, one symbol") produce passwords like Password1! that are weak in practice. Current guidance puts length first, then unpredictability: not a common password, not a keyboard pattern, not the user's own name. A useful validator reports two things: a list of requirements met or missed, so the user knows what to fix, and a strength level.

JavaScript
const COMMON = new Set(['password', '123456', '12345678', 'qwerty', 'letmein', 'welcome', 'admin', 'iloveyou', 'password1']);

export function checkPassword(pw) {
  const rules = [
    { id: 'length', label: 'At least 12 characters', ok: pw.length >= 12 },
    { id: 'lower', label: 'A lowercase letter', ok: /[a-z]/.test(pw) },
    { id: 'upper', label: 'An uppercase letter', ok: /[A-Z]/.test(pw) },
    { id: 'digit', label: 'A digit', ok: /\d/.test(pw) },
    { id: 'symbol', label: 'A symbol', ok: /[^A-Za-z0-9]/.test(pw) },
    { id: 'common', label: 'Not a common password', ok: !COMMON.has(pw.toLowerCase()) },
    { id: 'repeat', label: 'No run of 3 identical characters', ok: !/(.)\1\1/.test(pw) },
  ];
  const bits = estimateEntropyBits(pw);
  return { rules, bits, level: levelFor(pw, bits, rules) };
}

Estimating strength

A rough but honest measure is entropy in bits: the logarithm (base 2) of how many guesses an attacker would need if every character were chosen at random from the pool of character types you used.

JavaScript
export function estimateEntropyBits(pw) {
  if (!pw) return 0;
  let pool = 0;
  if (/[a-z]/.test(pw)) pool += 26;
  if (/[A-Z]/.test(pw)) pool += 26;
  if (/\d/.test(pw)) pool += 10;
  if (/[^A-Za-z0-9]/.test(pw)) pool += 32;
  const bits = pw.length * Math.log2(pool);
  const unique = new Set(pw).size;
  return Math.round(bits * Math.min(1, unique / (pw.length * 0.6)));   // penalize few distinct characters
}

function levelFor(pw, bits, rules) {
  if (!rules.find((r) => r.id === 'common').ok) return 'weak';
  if (bits < 40) return 'weak';
  if (bits < 60) return 'fair';
  if (bits < 80) return 'good';
  return 'strong';
}

The number is an upper bound: it assumes random characters, so a human-chosen phrase like Summer2024! scores higher than it deserves. That is why the common-password check forces weak regardless of the score. Real products use a library such as zxcvbn, which also knows dictionary words, names, dates and keyboard walks, and check the password against breach lists with a k-anonymity API, so the password itself never leaves the device.

The meter in React Native

JSX
const COLORS = { weak: '#dc2626', fair: '#f59e0b', good: '#84cc16', strong: '#16a34a' };
const WIDTH = { weak: '25%', fair: '50%', good: '75%', strong: '100%' };

function StrengthMeter({ password }) {
  const { rules, level } = checkPassword(password);
  return (
    <View accessible accessibilityLabel={`Password strength: ${level}`}>
      <View style={{ height: 6, backgroundColor: '#e2e8f0', borderRadius: 3 }}>
        <View style={{ width: WIDTH[level], height: 6, backgroundColor: COLORS[level], borderRadius: 3 }} />
      </View>
      {rules.map((r) => (
        <Text key={r.id} style={{ color: r.ok ? '#16a34a' : '#64748b' }}>{r.ok ? 'โœ“' : 'โ—‹'} {r.label}</Text>
      ))}
    </View>
  );
}

Do not rely on colour alone: the label and the check marks carry the same information for colour-blind users and screen readers.

Part 2: the generator

A good generated password is long, random and uses a secure source. The code below picks each character with an unbiased secure integer (the technique from the guessing and OTP project) and guarantees at least one character from each chosen group:

JavaScript
const SETS = {
  lower: 'abcdefghijkmnopqrstuvwxyz',          // l is left out: it looks like 1
  upper: 'ABCDEFGHJKLMNPQRSTUVWXYZ',           // I and O are left out
  digit: '23456789',                           // 0 and 1 are left out
  symbol: '!@#$%^&*-_=+?',
};

export function generatePassword({ length = 16, sets = ['lower', 'upper', 'digit', 'symbol'] }, randomInt) {
  const groups = sets.map((s) => SETS[s]);
  const all = groups.join('');
  const chars = groups.map((g) => g[randomInt(g.length)]);          // one from each group
  while (chars.length < length) chars.push(all[randomInt(all.length)]);
  for (let i = chars.length - 1; i > 0; i--) {                      // Fisher-Yates shuffle
    const j = randomInt(i + 1);
    [chars[i], chars[j]] = [chars[j], chars[i]];
  }
  return chars.join('');
}

The randomInt(n) function passed in must come from expo-crypto, not Math.random. Taking it as a parameter also lets the demo use a fixed generator for repeatable output.

Part 3: the manager

What to store, and where

Data Where Why
Site name, username normal storage is acceptable not secret by itself, but still personal
Passwords expo-secure-store (iOS Keychain, Android Keystore) encrypted by the OS, never in AsyncStorage or logs
The vault key (if you encrypt a larger blob) SecureStore the key must be as protected as the secrets

AsyncStorage is plain text on the device, so it is the wrong place for a password (see Storing Data). SecureStore has a size limit per value (about 2 KB on some platforms), so store one item per entry, with a key such as vault:<id>, and keep a list of ids elsewhere.

JavaScript
import * as SecureStore from 'expo-secure-store';

export const vault = {
  async save(entry) {
    await SecureStore.setItemAsync(`vault:${entry.id}`, JSON.stringify(entry), {
      keychainAccessible: SecureStore.WHEN_UNLOCKED_THIS_DEVICE_ONLY,
    });
  },
  async load(id) {
    const raw = await SecureStore.getItemAsync(`vault:${id}`);
    return raw ? JSON.parse(raw) : null;
  },
  async remove(id) {
    await SecureStore.deleteItemAsync(`vault:${id}`);
  },
};

WHEN_UNLOCKED_THIS_DEVICE_ONLY keeps the item from being backed up to another device and readable only while the phone is unlocked.

The rules of showing a secret

  1. Masked by default. Use secureTextEntry on the field, and show โ€ขโ€ขโ€ขโ€ขโ€ขโ€ขโ€ขโ€ข in the list. A "show" toggle reveals one password at a time, and hides it again after a few seconds.
  2. Gate the vault. Ask for biometrics or the device passcode when the app opens (expo-local-authentication: LocalAuthentication.authenticateAsync({ promptMessage: 'Unlock vault' })), and lock again when the app goes to the background (listen to AppState).
  3. Never log secrets, never put them in navigation params (they can end up in saved state and deep links) and never send them to analytics.
  4. Copy carefully. Clipboard.setStringAsync(password) is convenient but other apps can read the clipboard. Clear it after about 30 seconds, and on Android 13 and later mark it sensitive where the library allows.
  5. Hide the app switcher preview. Use a blur or a blank screen when the app is backgrounded, so the recents list does not show passwords (expo-screen-capture can also block screenshots on sensitive screens).
  6. Check every input. Validate that the site and password are not empty, and warn when the chosen password is weak or already used for another site.

Searching and editing

Keep the list in state and derive the visible rows from a search query, exactly as in the notes app: entries.filter((e) => e.site.toLowerCase().includes(q)). Editing reuses the same form, and upsert replaces an entry with the same id. Give every entry an id generated once (for example with expo-crypto's randomUUID()), never use the site name as the key.

Validator, generator and vault logic (stand-in)

The scores show the limits of a simple meter. password is forced to weak by the common-list rule, aaaaaaaaaaaa loses points for having few distinct characters, a long passphrase with mixed characters scores well, and the generated 16-character password is strong. The vault shows masked passwords and reveals only the one you tap.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. Where should the passwords of a password manager be stored?

    AsyncStorage is unencrypted plain text. SecureStore uses the operating system's protected storage.
  2. 2. Why does the validator force 'weak' for a common password even if its entropy estimate is high?

    The entropy estimate is an upper bound for random choices. Known passwords are guessed first by attackers.
  3. 3. Why should the password generator use a cryptographically secure random source?

    Passwords are secrets. They need unpredictable randomness such as the platform's secure generator.
  4. 4. Which is a good practice for showing a stored password?

    Secrets are masked by default. Logs and navigation params can leak them.

Summary

  • A validator reports met and missed rules plus a strength level; length and unpredictability matter more than character-class rules, and a common-password check overrides the score.
  • The entropy estimate is an upper bound; real products use zxcvbn and breach-list checks.
  • A generator uses a secure random source, unbiased selection, at least one character from each group and a shuffle.
  • Store secrets only in SecureStore, one item per entry; mask by default, gate with biometrics, never log, and clear the clipboard.
  • Use proven platform credential features in a real product; do not invent cryptography.

Next: Project: Blog App and Rich Text Editor.