npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@molecule/app-password-generator-react

v1.0.2

Published

Configurable secure password generator UI with length slider + character class toggles + regenerate + copy-to-clipboard

Readme

@molecule/app-password-generator-react

Auto-generated, AI-first package reference for the molecule.dev ecosystem. It is written to be read by coding agents as much as by people, and is generated from this package's source — edit src/index.ts JSDoc, not this file.

React password generator feature for molecule.dev.

Exports <PasswordGenerator> — a configurable, cryptographically-secure password generator UI (length slider, character-class toggles, copy + regenerate buttons, optional onPick for wiring into forms / password-manager save flows).

Quick Start

import { useState } from 'react'
import { PasswordGenerator } from '@molecule/app-password-generator-react'

function NewLoginForm() {
  const [password, setPassword] = useState('')
  return (
    <>
      <input type="password" value={password} onChange={(e) => setPassword(e.target.value)} />
      <PasswordGenerator
        defaultLength={24}
        autoCopy
        onPick={(generated) => setPassword(generated)}
      />
    </>
  )
}

Type

feature

Installation

npm install @molecule/app-password-generator-react @molecule/app-i18n @molecule/app-react @molecule/app-ui @molecule/app-ui-react react
npm install -D @types/react

API

Interfaces

PasswordCharsetOptions

Character-class options that toggle which alphabets the generator draws from. At least one of these must be true for the generator to produce a password — when all four are off, the generator falls back to lowercase + digits to avoid an empty alphabet.

interface PasswordCharsetOptions {
  /** Include uppercase letters A-Z. Defaults to `true`. */
  uppercase: boolean
  /** Include lowercase letters a-z. Defaults to `true`. */
  lowercase: boolean
  /** Include digits 0-9. Defaults to `true`. */
  digits: boolean
  /** Include common symbols (`!@#$%^&*()-_=+[]{};:,.<>/?`). Defaults to `true`. */
  symbols: boolean
  /** Skip visually-similar glyphs (`0`, `O`, `o`, `1`, `l`, `I`). Defaults to `false`. */
  noSimilar: boolean
  /** Skip ambiguous specials (space + `'"~\``). Defaults to `false`. */
  noAmbiguous: boolean
}

PasswordGeneratorProps

Props for <PasswordGenerator>.

interface PasswordGeneratorProps {
  /** Initial password length. Clamped to `[8, 64]`. Defaults to `20`. */
  defaultLength?: number
  /**
   * Optional initial charset overrides. Anything you don't supply
   * inherits the default (`uppercase`, `lowercase`, `digits`, `symbols`
   * all `true`; `noSimilar` and `noAmbiguous` `false`).
   */
  defaultCharset?: Partial<PasswordCharsetOptions>
  /**
   * Called when the user clicks "Use this password". Consumer wires
   * this to whatever form/secret store should receive the password.
   */
  onPick?: (password: string) => void
  /**
   * If `true`, every freshly-generated password is also written to the
   * clipboard automatically. Defaults to `false`.
   */
  autoCopy?: boolean
  /** Optional aria-label override on the read-only password output. */
  ariaLabel?: string
  /** Optional `data-mol-id` attribute on the root element. */
  dataMolId?: string
  /** Extra wrapper classes. */
  className?: string
}

Functions

buildCharset(charset)

Build the character pool for the supplied charset settings. If every inclusion toggle is off, falls back to lowercase + digits so the generator never has an empty alphabet to draw from.

function buildCharset(charset: PasswordCharsetOptions): string
  • charset — Charset toggles.

Returns: Concatenated allowed-character pool, deduplicated.

clampLength(n)

Clamp n into the [MIN_LENGTH, MAX_LENGTH] range.

function clampLength(n: number): number

generatePassword(length, charset)

Generate one cryptographically-secure password of the requested length using the supplied charset.

Uses rejection sampling on each 32-bit integer to avoid modulo bias — any value above floor(2^32 / pool) * pool is discarded and resampled.

function generatePassword(length: number, charset: PasswordCharsetOptions): string
  • length — Password length. Clamped to [8, 64].
  • charset — Charset toggles.

Returns: A freshly-generated password.

PasswordGenerator(props)

Cryptographically-secure password generator UI.

Renders a length slider (MIN_LENGTH-MAX_LENGTH), six character-class toggles (uppercase / lowercase / digits / symbols / no-similar / no-ambiguous), a copyable read-only output, a regenerate button, and a "Use this password" picker that fires onPick(password).

Randomness is sourced via crypto.getRandomValues (see ./generator.ts). All styling flows through getClassMap() and all user-visible strings through t() — no Tailwind class strings, no hardcoded text.

function PasswordGenerator({
  defaultLength = 20,
  defaultCharset,
  onPick,
  autoCopy = false,
  ariaLabel,
  dataMolId,
  className,
}: PasswordGeneratorProps): JSX.Element
  • props — Component props.

Returns: The rendered password generator.

Constants

DEFAULT_CHARSET

Default charset settings.

const DEFAULT_CHARSET: PasswordCharsetOptions

MAX_LENGTH

Maximum allowed length for the slider.

const MAX_LENGTH: 64

MIN_LENGTH

Minimum / maximum allowed length for the slider.

const MIN_LENGTH: 8

Injection Notes

Requirements

Peer dependencies:

  • @molecule/app-i18n ^1.0.1
  • @molecule/app-react ^1.0.1
  • @molecule/app-ui ^1.0.1
  • @molecule/app-ui-react ^1.0.1
  • react ^18.0.0 || ^19.0.0

Runtime Dependencies

  • @molecule/app-i18n
  • @molecule/app-react
  • @molecule/app-ui
  • @molecule/app-ui-react
  • react

Companion locale bond: @molecule/app-locales-password-generator. Copy/autoCopy use the async Clipboard API, which is unavailable on insecure (non-HTTPS, non-localhost) origins — the write fails silently and no "Copied!" confirmation appears; the user can still select the read-only field or click "Use this password". Generation itself needs crypto.getRandomValues (browsers + Node 20; it throws where WebCrypto is missing, e.g. very old SSR runtimes).

Translations

Translation strings are provided by @molecule/app-locales-password-generator.