Skip to content
Jennifer Programming Language

password API reference

Password generation, validation, and complexity scoring against a policy schema. A Schema names the allowed character classes (lowercase, uppercase, digits, symbols), a length range, and per-class minimum counts; generate(schema) produces a conforming password, validate(schema, pw) reports whether a password meets the policy (and why not), and complexity(pw) estimates a password's strength in bits of entropy.

Randomness comes from the crypto library's crypto-grade source (character choice and the final shuffle), so a generated password is unpredictable and safe to mint as a real credential. Pure .j over crypto / strings / convert; runs on both binaries.

Import with import "password.j" as password;. See the password guide for prose and examples.

Functions

password.complexity(pw as string)

Estimate a password's strength. The alphabet size is the sum of the class sizes present (lower/upper 26 each, digits 10, symbols the default-set size), and entropy is length * log2(alphabet) bits.

Parameters

  • pw {string} - the password

Returns {Strength} - length, class count, pool size, entropy bits, and a label

password.generate(s as Schema)

Generate a password conforming to the schema: a length picked in [minLength, maxLength], at least the per-class minimums, the remainder drawn from the enabled alphabet, then shuffled.

Parameters

  • s {Schema} - the policy

Returns {string} - a fresh password

Throws

  • {Error} - kind "password" if the schema is infeasible (no classes, an empty required pool, or minimums that exceed the length)

password.schema()

A strong default policy: exactly 16 characters, all four classes, at least one of each, the default symbol set, ambiguous glyphs allowed.

Returns {Schema} - the default policy

password.validate(s as Schema, pw as string)

Validate a password against a schema. Checks the length bounds and each per-class minimum; it does not reject characters outside the alphabet (a policy sets minimums, not a whitelist).

Parameters

  • s {Schema} - the policy
  • pw {string} - the password to check

Returns {Report} - valid plus the list of failed-rule reasons

password.withClasses(s as Schema, lo as bool, up as bool, dig as bool, sym as bool)

Copy a schema with new class enables (which classes appear in generation).

Parameters

  • s {Schema} - the base schema
  • lo {bool} - lowercase
  • up {bool} - uppercase
  • dig {bool} - digits
  • sym {bool} - symbols

Returns {Schema} - a fresh schema

password.withLength(s as Schema, lo as int, hi as int)

Copy a schema with a new length range (set lo == hi for a fixed length).

Parameters

  • s {Schema} - the base schema
  • lo {int} - minimum length
  • hi {int} - maximum length

Returns {Schema} - a fresh schema

password.withMinimums(s as Schema, lo as int, up as int, dig as int, sym as int)

Copy a schema with new per-class minimum counts.

Parameters

  • s {Schema} - the base schema
  • lo {int} - minimum lowercase
  • up {int} - minimum uppercase
  • dig {int} - minimum digits
  • sym {int} - minimum symbols

Returns {Schema} - a fresh schema

password.withSymbolSet(s as Schema, setChars as string)

Copy a schema with a replacement symbol set.

Parameters

  • s {Schema} - the base schema
  • setChars {string} - the symbol characters to draw from

Returns {Schema} - a fresh schema

password.withoutAmbiguous(s as Schema)

Copy a schema that excludes ambiguous glyphs (0 O o 1 l I |) from generation.

Parameters

  • s {Schema} - the base schema

Returns {Schema} - a fresh schema

Structs

password.Report

A validation result: whether the password conforms, and a list of the failed rules (empty when valid).

FieldTypeDescription
validbooltrue when every rule passed
reasonslist of stringhuman-readable failed rules

password.Schema

A password policy: allowed classes, a length range, per-class minimum counts, the symbol set, and whether to drop ambiguous glyphs.

FieldTypeDescription
minLengthintshortest allowed length (also the generated length floor)
maxLengthintlongest allowed length (generation picks in the range)
lowerboolinclude lowercase in the generation alphabet
upperboolinclude uppercase
digitsboolinclude digits
symbolsboolinclude symbols (from symbolSet)
symbolSetstringthe symbol characters to draw from
minLowerintminimum lowercase (generation guarantees, validation requires)
minUpperintminimum uppercase
minDigitsintminimum digits
minSymbolsintminimum symbols
excludeAmbiguousbooldrop ambiguous glyphs (0 O o 1 l I |) from generation

password.Strength

An estimated-strength summary of a password.

FieldTypeDescription
lengthintcharacter count
classesinthow many of the four classes are present (0-4)
poolSizeintthe estimated alphabet size (guessing space per char)
entropyfloatestimated bits of entropy (length * log2(poolSize))
labelstringa qualitative band: very weak / weak / reasonable / strong / very strong