zxcvbn-ts
Guide
Demo
Changelog
GitHub
Guide
Demo
Changelog
GitHub
  • Guide

    • Introduction
    • Getting started
    • Options
    • Languages
    • Filtering custom words
    • Matcher
    • Pwned matcher
    • Lazy loading
    • Best Practices
    • Examples
    • Framework examples
    • TypeScript
    • Comparison
    • Migration
  • Demo

    • Demo

Languages

zxcvbn-ts is available for multiple languages. If your language is not supported you can set the options by yourself.

Current supported languages:

  • Arabic
  • Chinese
  • Croatian
  • Czech
  • Danish (Denmark)
  • Dutch (Belgium)
  • English
  • Farsi (Persian)
  • Finnish
  • French
  • German
  • Indonesia
  • Italian
  • Japanese
  • Korean
  • Kurmanjî (Kurdish)
  • Polish
  • Portuguese (Brazil)
  • Romanian
  • Russian
  • Spanish (Spain)
  • Thai
  • Turkish

Feedback

By default, zxcvbn-ts uses keys as feedback. This way you can integrate zxcvbn-ts into your own translation system. If you don't have an own translation system or want to use predefined translation you can use one of the language packs. Each language pack has its own translation file that you can use like this:

import { ZxcvbnFactory } from '@zxcvbn-ts/core'
import { translations } from '@zxcvbn-ts/language-en'

const password = 'somePassword'
const options = {
  translations,
}

const zxcvbn = new ZxcvbnFactory(options)
zxcvbn.check(password)

Translation keys

Without translations, feedback.warning and feedback.suggestions contain these keys (without the group prefix) and crackTimes.*.display contains the timeEstimation key. Use crackTimes.*.base for the number in your own translation. If you pass your own translations, every key has to be there, as a string or a function, otherwise ZxcvbnFactory throws Invalid translations object, missing or invalid keys: <keys>, listing the keys to fix. This includes the pwned keys, even if you don't use the pwned matcher. A custom matcher can return its own feedback and doesn't need a key here.

KeyEnglish translation
warnings.straightRowStraight rows of keys on your keyboard are easy to guess.
warnings.keyPatternShort keyboard patterns are easy to guess.
warnings.simpleRepeatRepeated characters like "aaa" are easy to guess.
warnings.extendedRepeatRepeated character patterns like "abcabcabc" are easy to guess.
warnings.sequencesCommon character sequences like "abc" are easy to guess.
warnings.recentYearsRecent years are easy to guess.
warnings.datesDates are easy to guess.
warnings.topTenThis is a heavily used password.
warnings.topHundredThis is a frequently used password.
warnings.commonThis is a commonly used password.
warnings.similarToCommonThis is similar to a commonly used password.
warnings.wordByItselfSingle words are easy to guess.
warnings.namesByThemselvesSingle names or surnames are easy to guess.
warnings.commonNamesCommon names and surnames are easy to guess.
warnings.userInputsThere should not be any personal or page related data.
warnings.pwnedYour password was exposed by a data breach on the Internet.
suggestions.l33tAvoid predictable letter substitutions like '@' for 'a'.
suggestions.reverseWordsAvoid reversed spellings of common words.
suggestions.allUppercaseCapitalize some, but not all letters.
suggestions.capitalizationCapitalize more than the first letter.
suggestions.datesAvoid dates and years that are associated with you.
suggestions.recentYearsAvoid recent years.
suggestions.associatedYearsAvoid years that are associated with you.
suggestions.sequencesAvoid common character sequences.
suggestions.repeatedAvoid repeated words and characters.
suggestions.longerKeyboardPatternUse longer keyboard patterns and change typing direction multiple times.
suggestions.anotherWordAdd more words that are less common.
suggestions.useWordsUse multiple words, but avoid common phrases.
suggestions.noNeedYou can create strong passwords without using symbols, numbers, or uppercase letters.
suggestions.pwnedIf you use this password elsewhere, you should change it.
timeEstimation.ltSecondless than a second
timeEstimation.second{base} second
timeEstimation.seconds{base} seconds
timeEstimation.minute{base} minute
timeEstimation.minutes{base} minutes
timeEstimation.hour{base} hour
timeEstimation.hours{base} hours
timeEstimation.day{base} day
timeEstimation.days{base} days
timeEstimation.month{base} month
timeEstimation.months{base} months
timeEstimation.year{base} year
timeEstimation.years{base} years
timeEstimation.centuriescenturies

Pluralization

For the timeEstimation translations, you can use a string with a {base} placeholder or a function for more complex pluralization rules.

const translations = {
  warnings: {
    // ...
  },
  suggestions: {
    // ...
  },
  timeEstimation: {
    ltSecond: 'less than a second',
    second: '{base} second',
    seconds: (value) => {
      if (value === 2) return 'exactly two seconds'
      return `${value} seconds`
    },
    // ...
  },
}

Dictionary

By default, zxcvbn-ts doesn't use any dictionaries to let the developer decide how much of the library will be used. This makes the library tiny but inefficient compared to the original library. It is recommended to use at least the common and English language package.

import { ZxcvbnFactory } from '@zxcvbn-ts/core'
import * as zxcvbnCommonPackage from '@zxcvbn-ts/language-common'
import * as zxcvbnEnPackage from '@zxcvbn-ts/language-en'

const password = 'somePassword'
const options = {
  dictionary: {
    ...zxcvbnCommonPackage.dictionary,
    ...zxcvbnEnPackage.dictionary,
  },
}

const zxcvbn = new ZxcvbnFactory(options)
zxcvbn.check(password)

Keyboard patterns

By default, zxcvbn-ts doesn't use any keyboard patterns to let the developer decide how much of the library will be used. It is recommended to use at least the common keyboard patterns.

import { ZxcvbnFactory } from '@zxcvbn-ts/core'
import * as zxcvbnCommonPackage from '@zxcvbn-ts/language-common'

const password = 'somePassword'
const options = {
  graphs: zxcvbnCommonPackage.adjacencyGraphs,
}

const zxcvbn = new ZxcvbnFactory(options)
zxcvbn.check(password)

Add a new language package

To add a missing language package you need to do the following things:

  • Clone the repo.
  • Install dependencies with yarn install.
  • Create a new language package inside the packages/languages directory. You need following file structure:
- src
  - translations.ts
- package.json
- README.md
- tsconfig.json
  • Fill src/translations.ts with translations for your language. You can use strings with {base} or functions for timeEstimation if your language has complex pluralization rules.

  • Adjust README.md file as appropriate.

  • Find some reliable sources for some dictionaries. As a minimum, you need to have a source for firstname, lastname and commonWords. For common words you can use the OpenSubtitles frequency lists like the other languages (https://object.pouta.csc.fi/OPUS-OpenSubtitles/v2024/freq/XX.freq.gz with the CommonWordsGenerator) - there are a lot of languages available.

  • Add your language and sources to the generator list in ./data-scripts/lists.ts.

    There is a default generator that takes simple lists that have only single words per line and can have occurrences of that word with a space separator. For example something like this:

    John
    Debra
    Billy
    

    or:

    you 23123
    i 12345
    the 234
    

    If your list is more complex you need to write your own generator like the password generator or the keyboard generator

  • Run yarn generate:languageData. This will generate the JSON files and index.ts. The dictionary keys in index.ts get your language code as suffix, e.g. commonWords-de.

  • During debugging, it might be easy to only generate the language files for one language, use yarn generate:languageData nl-be for example.

  • Create a pull request to the master branch.

  • (Optional) Use the Wikipedia extractor; one of the maintainers can do this but this will increase the time until it is merged.

    • Get the wikipedia dump for your language from https://dumps.wikimedia.org/XXwiki/latest/XXwiki-latest-pages-articles.xml.bz2 where XX is your language like en or de.

    • Install wikiextractor: pip install wikiextractor. Currently, with v3.0.4 it only works correctly on Linux.

    • Run wikiextractor:

      wikiextractor --no-templates -o data-scripts/wikiExtractor/extracts XXwiki-latest-pages-articles.xml.bz2
      
    • Run yarn run wikipediaExtractor to generate wikipedia.json from all the files inside the extracts folder.

    • Move wikipedia.json into your language package.

Edit this page
Last Updated: 11/14/26, 7:35 PM
Contributors: MrWook
Prev
Options
Next
Filtering custom words