MCPcopy Index your code
hub / github.com/1Password/password-rules-parser

github.com/1Password/password-rules-parser @v1.1.0

Chat with this repo
repository ↗ · DeepWiki ↗ · release v1.1.0 ↗ · + Follow
62 symbols 109 edges 4 files 28 documented · 45%
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

password-rules-parser

crate documentation Crates.io version Crates.io downloads dependency status CI

Rust parser for the HTML passwordrules attribute, a proposal for an HTML attribute that allows services to specify their password requirements in a machine-readable format.

This spec is primarily being backed by Apple, and their tools and docs can be found here.

See this crate's documentation for our own primer.

Example

This example can be run via cargo run --example parse.

use password_rules_parser::{parse_password_rules, CharacterClass};

let password_rules = "minlength: 8; maxlength: 32; required: lower, upper; required: digit; allowed: [-_./\\@$*&!#];";
let parsed_rules =
    parse_password_rules(password_rules, true).expect("failed to parse password rules");

assert_eq!(parsed_rules.min_length.unwrap(), 8);
assert_eq!(parsed_rules.max_length.unwrap(), 32);
// This password rule does not place a restriction on consecutive characters
assert!(parsed_rules.max_consecutive.is_none());
assert_eq!(
    parsed_rules.allowed,
    vec![CharacterClass::Custom(vec![
        '!', '#', '$', '&', '*', '-', '.', '/', '@', '\\', '_',
    ])]
);
assert_eq!(
    parsed_rules.required,
    vec![
        vec![CharacterClass::Upper, CharacterClass::Lower],
        vec![CharacterClass::Digit]
    ]
);

// The above information can be used to make informed decisions about what password
// to generate for use with a specific service

You can try parsing arbitrary rules with this tool via cargo run --example cli.

MSRV

The Minimum Supported Rust Version is currently 1.46.0. This will be bumped to the latest stable version of Rust when needed.

Credits

Made with ❤️ by the 1Password team, with appreciation for the wonderful nom parsing library.

License

Licensed under either of Apache License, Version 2.0 or MIT license at your option.

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in this crate by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

Extension points exported contracts — how you extend this code

WithTagError (Interface)
Extension trait for nom::error::ParseError that allows for collecting the failed tag in the event of a mismatch, similar [2 …
src/error.rs

Core symbols most depended-on inside this repo

chars
called by 8
src/lib.rs
tag_no_case
called by 7
src/lib.rs
space_surround
called by 6
src/lib.rs
parse_generic_rule
called by 5
src/lib.rs
set_range
called by 5
src/lib.rs
check_or_extract
called by 5
src/lib.rs
canonicalize
called by 4
src/lib.rs
apply
called by 3
src/lib.rs

Shape

Function 30
Method 20
Class 6
Enum 5
Interface 1

Languages

Rust100%

Modules by API surface

src/lib.rs44 symbols
src/error.rs16 symbols
examples/parse.rs1 symbols
examples/cli.rs1 symbols

For agents

$ claude mcp add password-rules-parser \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact