Functional Weave
Code in Rust

auth.password-policy@1.0.1

impl/python/password_policy.py

826 bytes · the Python implementation · view raw

Imports name this capability’s declared dependencies, which fune builds next to it in your project; each one links to its page.

from .auth_password_policy_data import POLICIES  ← this capability’s own data, compiled from data/policies.json into the same file by fune build
from .auth_password_policy_types import PasswordPolicy


def password_policy(name: str) -> PasswordPolicy:
    """A named policy from the data, so a browser and an API that both ask for
    "nist-800-63b-4-single-factor" enforce exactly the same numbers."""
    for row in POLICIES:
        if row.name == name:
            return PasswordPolicy(
                name=row.name,
                min_length=row.min_length,
                max_length=row.max_length,
                min_character_classes=row.min_character_classes,
                block_common=row.block_common,
                block_personal=row.block_personal,
            )
    raise ValueError(
        'unknown password policy "%s"; known policies: %s' % (name, ", ".join(row.name for row in POLICIES))
    )