Skip to content
Workforce IdentityMarkdown

Password rules

Refuse weak passwords whenever they are set, by whoever sets them, with rules for capitals, digits, banned characters and values, and the user's own details.

AvailableAPI

Password rules make the realm refuse a weak password at the moment it’s set, whether a user chooses it, an administrator sets it, or a script writes it through the API. You declare the rules once on the type that holds the password, and every write of that field is held to them.

Passwords matter less in a realm where users sign in with passkeys, but every realm still lets a user sign in with a password and an authenticator app. These rules keep that path from resting on password1.

A new realm has no password rules. It sets no minimum length and no rule, so any password is accepted until you add them. Add at least a minimum length when you set up the realm (see Set it up).

  • Who can do it: a realm administrator, in a group that holds RealmOwner (Delegated administration).
  • Where: today the rules are set through the API (Call the API shows how to get $CVYUH_SESSION). Every password set afterwards is held to them, whoever sets it.

Each rule is a check on the password field, run on every write before the password is hashed and stored. A write that breaks a rule is refused with 400 and POLICY_VIOLATION, naming each rule it broke, and nothing is saved.

RuleA password must
at-least-capitalsHold at least count capital letters (1 if absent)
at-least-numbersHold at least count digits (1 if absent)
cannot-contain-charactersHold none of the characters listed in chars
cannot-contain-valueNot contain the text in value
cannot-contain-othersNot contain the value of any field listed in fields, such as the username (uid)

A minimum length is the field’s own minLength in the type’s schema. The realm keeps only a hash of the password, never the password itself.

Rules are declared in a type’s policies, keyed by the field they check. For the realm’s users, that’s the user type’s password field, passwordHash, which takes the password as written and stores only its hash. A type is replaced whole, through the admin API (Call the API shows how to get a session):

  1. Read the user type, and keep its ETag:

    Terminal window
    curl https://foobar.cvyuh.com/api/v0/am/types/v1/user \
    -H "Cookie: x-cvyuh-token=$CVYUH_SESSION"
  2. Add the rules to its policies, and send the whole definition back with the ETag as If-Match:

    Terminal window
    curl -X PUT https://foobar.cvyuh.com/api/v0/am/types/v1/user \
    -H "Cookie: x-cvyuh-token=$CVYUH_SESSION" \
    -H 'If-Match: "<rev>"' \
    -H "Content-Type: application/json" \
    -d '{ "name": "user", "…": "the rest of the definition, as you read it",
    "policies": {
    "passwordHash": [
    { "id": "at-least-capitals", "count": 1 },
    { "id": "at-least-numbers", "count": 2 },
    { "id": "cannot-contain-characters", "chars": " " },
    { "id": "cannot-contain-others", "fields": ["uid", "email"] }
    ]
    } }'

    The definition you send replaces the type’s. Send everything you read, changed only where you mean it. A write with no If-Match is refused 428.

  3. To add a minimum length, set minLength on the password field in the same definition, for example "passwordHash": { "…": "as you read it", "minLength": 12 }.

A password that breaks a rule is refused when it’s set, with 400 and POLICY_VIOLATION, naming each rule it broke. The old password stays in place. Signing in is never refused by a rule: a password set before the rule existed still works until it’s changed.

Setting or limitDefaultRange
Minimum length (minLength)noneany length you choose
Rules on the password fieldnoneany of the five rules, each once or more
count on at-least-capitals, at-least-numbers1any whole number
SymptomCauseFix
428 when saving the typeNo If-Match headerRead the type and send its ETag
412 when saving the typeSomeone changed the type since you read itRead it again and reapply your change
A rule seems ignored for some usersTheir passwords were set before the ruleRules apply at the next change; ask those users to change their password

Every password change is a change to the user, recorded as UPDATED or PATCHED in their Change history (in the dashboard, Audit → Config), with the password itself left out. A change to the rules is a change to the user type, recorded the same way. A password change is also sent as a credential change to anyone following the user through Send signals.

  • Every write is checked, not only sign-up. A password set by an administrator or written through the API is held to the same rules.
  • Existing passwords aren’t checked again. A rule you add applies to the next time each password is set.
  • Older names still work. at-least-X-capitals, at-least-X-numbers and cannot-contain are accepted, and value is read where count is absent.
  • cannot-contain-others with no fields checks nothing.

Refusing a password used before, passwords that expire, refusing passwords found in known breaches, and a different set of rules per group of users. See What’s next for authentication.