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 policypw{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 schemalo{bool}- lowercaseup{bool}- uppercasedig{bool}- digitssym{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 schemalo{int}- minimum lengthhi{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 schemalo{int}- minimum lowercaseup{int}- minimum uppercasedig{int}- minimum digitssym{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 schemasetChars{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).
| Field | Type | Description |
|---|---|---|
valid | bool | true when every rule passed |
reasons | list of string | human-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.
| Field | Type | Description |
|---|---|---|
minLength | int | shortest allowed length (also the generated length floor) |
maxLength | int | longest allowed length (generation picks in the range) |
lower | bool | include lowercase in the generation alphabet |
upper | bool | include uppercase |
digits | bool | include digits |
symbols | bool | include symbols (from symbolSet) |
symbolSet | string | the symbol characters to draw from |
minLower | int | minimum lowercase (generation guarantees, validation requires) |
minUpper | int | minimum uppercase |
minDigits | int | minimum digits |
minSymbols | int | minimum symbols |
excludeAmbiguous | bool | drop ambiguous glyphs (0 O o 1 l I |) from generation |
password.Strength
An estimated-strength summary of a password.
| Field | Type | Description |
|---|---|---|
length | int | character count |
classes | int | how many of the four classes are present (0-4) |
poolSize | int | the estimated alphabet size (guessing space per char) |
entropy | float | estimated bits of entropy (length * log2(poolSize)) |
label | string | a qualitative band: very weak / weak / reasonable / strong / very strong |