CUI

Components / Inputs

Password strength

A meter under a password field that scores the password from too short to strong.

Functions: cui_password_strength

Password strength

Usage

static char pw[64];
cui_input(ui, "pw", pw, sizeof pw, .label = "Password", .password = true);
int score = cui_password_strength(ui, pw);   /* 0 too short .. 4 strong */

Returns the score from 0 to 4 and draws four segments with a word beside them: "Too short", "Weak", "Fair", "Good" or "Strong". pw is your string, the same buffer the field edits; it is only read, and NULL or an empty string scores 0 and shows no word. The score counts simple rules: one point each for 8 characters, for 12 characters, for mixing lower and upper case, for a digit and for any other character, capped at 4, and at 1 while the password is shorter than 8. It does not know common passwords, so enforce your real policy with the field's error. The meter uses a fixed internal id, so two meters in one id scope need a cui_id_scope each.

Options of cui_input

OptionTypeDefaultDescription
.labelconst char *label above the field
.placeholderconst char *Muted text shown while the field is empty.
.iconconst char *leading icon
.hintconst char *helper text below
.errorconst char *error text below (red)
.passwordboolshows dots instead of the text, with an eye button that reveals it
.disabledboolGreyed out, and takes no input.
.clearableboolx button when not empty
.autofocusboolTakes the keyboard focus when it first appears.
.read_onlyboolShows the value but does not let it be edited.
.sizecui_control_sizeOne of CUI_SIZE_MD, CUI_SIZE_SM or CUI_SIZE_LG.
.widthcui_sizeWidth: CUI_FILL, CUI_FIT, CUI_PX(n) or CUI_PCT(n); unset uses the component's own.
.heightfloattextarea: height in points; negative fills the space
.prefixconst char *muted text before the value, e.g. "$" or "https://"
.suffixconst char *muted text after the value, e.g. "USD" or "kg"

Related

  • Inline edit: Text that turns into a field when clicked, for renaming things in place.
  • One time code: A row of boxes for a verification code, filled by typing or pasting.
  • Scrub field: A number you change by dragging sideways on it, as in design and 3D tools.
  • Tag input: A field that turns typed words into removable chips, kept as a comma separated list.