{"id":13905517,"url":"https://github.com/nulab/zxcvbn4j","last_synced_at":"2025-04-12T21:21:57.160Z","repository":{"id":41168834,"uuid":"48521654","full_name":"nulab/zxcvbn4j","owner":"nulab","description":"This is a java port of zxcvbn, which is a JavaScript password strength generator.","archived":false,"fork":false,"pushed_at":"2024-07-15T08:52:07.000Z","size":2889,"stargazers_count":334,"open_issues_count":12,"forks_count":102,"subscribers_count":33,"default_branch":"main","last_synced_at":"2025-04-04T01:02:16.480Z","etag":null,"topics":["java","password","zxcvbn"],"latest_commit_sha":null,"homepage":null,"language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/nulab.png","metadata":{"files":{"readme":"README.ja.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2015-12-24T02:52:58.000Z","updated_at":"2025-04-02T01:18:54.000Z","dependencies_parsed_at":"2023-11-07T14:31:25.744Z","dependency_job_id":"3d47e8ad-61b5-481e-81e8-5e6dbb419d40","html_url":"https://github.com/nulab/zxcvbn4j","commit_stats":null,"previous_names":[],"tags_count":36,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nulab%2Fzxcvbn4j","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nulab%2Fzxcvbn4j/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nulab%2Fzxcvbn4j/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nulab%2Fzxcvbn4j/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/nulab","download_url":"https://codeload.github.com/nulab/zxcvbn4j/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248632527,"owners_count":21136703,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["java","password","zxcvbn"],"created_at":"2024-08-06T23:01:17.664Z","updated_at":"2025-04-12T21:21:57.131Z","avatar_url":"https://github.com/nulab.png","language":"Java","funding_links":[],"categories":["Java","安全"],"sub_categories":[],"readme":"\n# zxcvbn4j [![Build](https://github.com/nulab/zxcvbn4j/actions/workflows/build.yml/badge.svg)](https://github.com/nulab/zxcvbn4j/actions/workflows/build.yml) [![Coverage Status](https://coveralls.io/repos/nulab/zxcvbn4j/badge.svg?branch=master\u0026service=github)](https://coveralls.io/github/nulab/zxcvbn4j?branch=master) [![Maven Central](https://img.shields.io/maven-central/v/com.nulab-inc/zxcvbn.svg)](https://img.shields.io/maven-central/v/com.nulab-inc/zxcvbn.svg)\n\nzxcvbn4j は、JavaScriptのパスワード強度ジェネレータである[zxcvbn](https://github.com/dropbox/zxcvbn)をJavaにポーティングしたものです。\n\n**関連記事:**\n\n- [真のパスワード強度を測定する5つのアルゴリズム](https://nulab-inc.com/ja/blog/nulab/password-strength/)\n\n## 目次\n\n* [更新](#更新)\n* [特別な機能](#特別な機能)\n  + [内部辞書とキーボードのカスタマイズ](#内部辞書とキーボードのカスタマイズ)\n  + [フィードバックメッセージのローカライズ](#フィードバックメッセージのローカライズ)\n  + [デフォルトで様々な言語をサポート](#デフォルトで様々な言語をサポート)\n  + [JISキーボードに対応](#JISキーボードに対応)\n  + [パスワードの引数はStringだけでなくCharSequenceも受付可能](#パスワードの引数はStringだけでなくCharSequenceも受付可能)\n* [インストール](#インストール)\n* [開発](#開発)\n* [使い方](#使い方)\n  + [基本](#基本)\n  + [強度の情報](#強度の情報)\n* [辞書とキーボードのカスタマイズ](#辞書とキーボードのカスタマイズ)\n  + [クラスパスから取得したリソースを使用する](#クラスパスから取得したリソースを使用する)\n  + [HTTPを介して取得したリソースを使用する](#HTTPを介して取得したリソースを使用する)\n  + [クラスパス以外のファイルのリソースを使用する](#クラスパス以外のファイルのリソースを使用する)\n  + [全てのデフォルトリソースを使用する](#全てのデフォルトリソースを使用する)\n  + [デフォルトリソースから選択して使用する](#デフォルトリソースから選択して使用する)\n* [フィードバックメッセージのローカライズ](#フィードバックメッセージのローカライズ)\n    - [リソースバンドルを指定してローカライズする](#リソースバンドルを指定してローカライズする)\n    - [リソースバンドルのセットを使ってローカライズする](#リソースバンドルのセットを使ってローカライズする)\n* [要件](#要件)\n* [このライブラリを使用](#このライブラリを使用)\n* [バグ報告やご意見](#バグ報告やご意見)\n* [ライセンス](#ライセンス)\n\n## 更新\n\n| Ported Version | Original [zxcvbn](https://github.com/dropbox/zxcvbn/releases) Version |\n|----------------|-----------------------------------------------------------------------|\n| 1.2.3 - latest | [4.4.2](https://github.com/dropbox/zxcvbn/releases/tag/v4.4.2)        |\n| 1.2.1 - 1.2.2  | [4.4.1](https://github.com/dropbox/zxcvbn/releases/tag/v4.4.1)        |\n| 1.1.0 - 1.2.0  | [4.4.0](https://github.com/dropbox/zxcvbn/releases/tag/v4.4.0)        |\n| 1.0.0 - 1.0.2  | [4.2.0](https://github.com/dropbox/zxcvbn/releases/tag/4.2.0)         |\n\n## 特別な機能\n\n### 内部辞書とキーボードのカスタマイズ\n\n* 測定アルゴリズムが使用する辞書とキーボードレイアウトをカスタマイズできます。\n\n### フィードバックメッセージのローカライズ\n\n* フィードバックメッセージを任意の言語にローカライズできます。\n\n### デフォルトで様々な言語をサポート\n\n測定結果のフィードバックメッセージに対応する言語\n\n- English ([default](./src/main/resources/com/nulabinc/zxcvbn/messages.properties))\n- Japanese ([ja](./src/main/resources/com/nulabinc/zxcvbn/messages_ja.properties))\n- Dutch ([nl](./src/main/resources/com/nulabinc/zxcvbn/messages_nl.properties))\n- German ([de](./src/main/resources/com/nulabinc/zxcvbn/messages_de.properties))\n- French ([fr](./src/main/resources/com/nulabinc/zxcvbn/messages_fr.properties))\n- Italian ([it](./src/main/resources/com/nulabinc/zxcvbn/messages_it.properties))\n- Spanish ([es](./src/main/resources/com/nulabinc/zxcvbn/messages_es.properties))\n- Portuguese ([pt](./src/main/resources/com/nulabinc/zxcvbn/messages_pt.properties))\n\n### JISキーボードに対応\n\n* 隣接したキー配列の照合処理にJISキーボードを対応\n\n### パスワードの引数はStringだけでなくCharSequenceも受付可能\n\n* これによりパスワードのフォーマットを柔軟に変更可能。\n* センシティブな中間オブジェクトにも文字列を使用しない。\n\n## インストール\n\nhttps://mvnrepository.com/artifact/com.nulab-inc/zxcvbn/1.9.0\n\nGradle:\n\n```\ncompile 'com.nulab-inc:zxcvbn:1.9.0'\n```\n\nMaven:\n\n```\n\u003cdependency\u003e\n  \u003cgroupId\u003ecom.nulab-inc\u003c/groupId\u003e\n  \u003cartifactId\u003ezxcvbn\u003c/artifactId\u003e\n  \u003cversion\u003e1.9.0\u003c/version\u003e\n\u003c/dependency\u003e\n```\n\n## 開発\n\n``` bash\n$ git clone https://github.com/nulab/zxcvbn4j.git\n$ cd ./zxcvbn4j\n$ ./gradlew build    # build\n$ ./gradlew test     # test\n$ ./gradlew jmh      # benchmark\n```\n\n## 使い方\n\n### 基本\n\n\n基本的な使い方です。Androidも同じようにご利用できます。\n\n``` java\nZxcvbn zxcvbn = new Zxcvbn();\nStrength strength = zxcvbn.measure(\"This is password\");\n```\n\n独自の辞書を追加したい場合は、第二引数にリスト\u003c文字列\u003eのタイプのキーワード一覧を渡します。\n\n``` java\nList\u003cString\u003e sanitizedInputs = new ArrayList();\nsanitizedInputs.add(\"nulab\");\nsanitizedInputs.add(\"backlog\");\nsanitizedInputs.add(\"cacoo\");\nsanitizedInputs.add(\"typetalk\");\n\nZxcvbn zxcvbn = new Zxcvbn();\nStrength strength = zxcvbn.measure(\"This is password\", sanitizedInputs);\n```\n\n### 強度の情報\n\n返却する結果は、\"Strength\"インスタンスです。[zxcvbn](https://github.com/dropbox/zxcvbn) が返却する結果とほぼ同じものです。\n\n```\n# パスワードの「乱雑さ」「複雑さ」を表す指標\nstrength.guesses\nstrength.guessesLog10\n\n# いくつかのシナリオに基づいたクラック時間の推測\nstrength.crackTimeSeconds\n{\n  # オンライン攻撃でパスワード認証に回数制限が有る場合\n  onlineThrottling100PerHour\n\n  # オンライン攻撃でパスワード認証に回数制限が無い場合\n  onlineNoThrottling10PerSecond\n\n  # オフライン攻撃で、bcrypt、scrypt、PBKDF2等を使ってハッシュ化している場合\n  offlineSlowHashing1e4PerSecond\n\n  # オフライン攻撃で、SHA-1、SHA-256またはMD5等を使ってハッシュ化している場合\n  offlineFastHashing1e10PerSecond\n}\n\n# strength.crackTimeSecondsを表示するために文字列化した値(秒未満、3時間、世紀 等)\nstrength.crackTimeDisplay\n\n\n# 0から4の整数\n# 0 弱い      （guesses \u003c 10^3 + 5）\n# 1 やや弱い   （guesses \u003c 10^6 + 5）\n# 2 普通      （guesses \u003c 10^8 + 5）\n# 3 強い      （guesses \u003c 10^10 + 5）\n# 4 とても強い （guesses \u003e= 10^10 + 5）\nstrength.score\n\n# 安全なパスワード作成に役立つフィードバック。(score \u003c= 2 のみ表示)\n{\n  # 警告文\n  warning\n\n  # 提案\n  suggestions\n}\n\n# 測定に用いたパターンのリスト\nstrength.sequence\n\n# 測定にかかった時間\nstrength.calc_time\n```\n\n## 辞書とキーボードのカスタマイズ\n\n`ZxcvbnBuilder`を使って測定処理で使用する辞書とキーボードをカスタマイズできます。\n\n### クラスパスから取得したリソースを使用する\n\nクラスパス上の独自の辞書ファイルやキーボードファイルを`ClasspathResource`を使って取得できます。\n辞書ファイルは`DictionaryLoader`を使ってロードします。\nキーボードファイルは`SlantedKeyboardLoader`か`AlignedKeyboardLoader`を使ってロードします。\n\n``` java\nZxcvbn zxcvbn = new ZxcvbnBuilder()\n        .dictionary(new DictionaryLoader(\"us_tv_and_film\", new ClasspathResource(\"/com/nulabinc/zxcvbn/matchers/dictionarys/us_tv_and_film.txt\")).load())\n        .keyboard(new SlantedKeyboardLoader(\"qwerty\", new ClasspathResource(\"/com/nulabinc/zxcvbn/matchers/keyboards/qwerty.txt\")).load())\n        .keyboard(new AlignedKeyboardLoader(\"keypad\", new ClasspathResource(\"/com/nulabinc/zxcvbn/matchers/keyboards/keypad.txt\")).load())\n        .build();\n```\n\n### HTTPを介して取得したリソースを使用する\n\n`Resource interface`を実装するとクラスパス以外の辞書・キーボードファイルも取得できます。\n以下のコードはHTTP(s)を使ってファイルを取得してロードしています。\n\n``` java\nURL dictionaryURL = new URL(\"https://example.com/foo/dictionary.txt\");\nResource myDictionaryResource = new MyResourceOverHTTP(dictionaryURL);\n\nURL keyboardURL = new URL(\"https://example.com/bar/keyboard.txt\");\nResource myKeyboardURLResource = new MyResourceOverHTTP(keyboardURL);\n\nZxcvbn zxcvbn = new ZxcvbnBuilder()\n        .dictionary(new DictionaryLoader(\"my_dictionary\", myDictionaryResource).load())\n        .keyboard(new SlantedKeyboardLoader(\"my_keyboard\", myKeyboardURLResource).load())\n        .build();\n\npublic class MyResourceOverHTTP implements Resource {\n\n    private URL url;\n\n    public MyResourceOverHTTP(URL url) {\n        this.url = url;\n    }\n\n    @Override\n    public InputStream getInputStream() throws IOException {\n        HttpURLConnection conn = (HttpURLConnection) this.url.openConnection();\n        return conn.getInputStream();\n    }\n}\n```\n\n### クラスパス以外のファイルのリソースを使用する\n\n以下のコードはクラスパス以外の他のディレクトリのファイルを取得してロードしています。\n\n``` java\nFile dictionaryFile = new File(\"/home/foo/dictionary.txt\");\nResource myDictionaryResource = new MyResourceFromFile(dictionaryFile);\n\nFile keyboardFile = new File(\"/home/bar/keyboard.txt\");\nResource myKeyboardURLResource = new MyResourceFromFile(keyboardFile);\n\nZxcvbn zxcvbn = new ZxcvbnBuilder()\n    .dictionary(new DictionaryLoader(\"my_dictionary\", myDictionaryResource).load())\n    .keyboard(new SlantedKeyboardLoader(\"my_keyboard\", myKeyboardURLResource).load())\n    .build();\n\npublic class MyResourceFromFile implements Resource {\n\n    private File file;\n\n    public MyResourceFromFile(File file) {\n        this.file = file;\n    }\n\n    @Override\n    public InputStream getInputStream() throws IOException {\n        return new FileInputStream(this.file);\n    }\n}\n```\n\n### 全てのデフォルトリソースを使用する\n\nStandardDictionariesを使ってデフォルトの辞書ファイルやキーボードをロードできます。\n`StandardDictionaries.loadAllDictionaries()`はデフォルトの全ての辞書ファイルをロードします。\n`StandardDictionaries.loadAllKeyboards()`はデフォルトの全てのキーボードファイルをロードします。\n\n``` java\nZxcvbn zxcvbn = new Zxcvbn();\n```\n\nor\n\n``` java\nZxcvbn zxcvbn = new ZxcvbnBuilder()\n    .dictionaries(StandardDictionaries.loadAllDictionaries())\n    .keyboards(StandardKeyboards.loadAllKeyboards())\n    .build();\n```\n\n### デフォルトリソースから選択して使用する\n\nデフォルトの辞書ファイルやキーボードから一部を選択してロードできます。\n\n``` java\nZxcvbn zxcvbn = new ZxcvbnBuilder()\n    .dictionary(StandardDictionaries.ENGLISH_WIKIPEDIA_LOADER.load())\n    .dictionary(StandardDictionaries.PASSWORDS_LOADER.load())\n    .keyboard(StandardKeyboards.QWERTY_LOADER.load())\n    .keyboard(StandardKeyboards.DVORAK_LOADER.load())\n    .build();\n```\n\n## フィードバックメッセージのローカライズ\n\nzxcvbn4jは英語で返却されるフィードバックメッセージを他の言語に変更可能です。\n\n#### リソースバンドルを指定してローカライズする\n\n``` java\n// パスワード強度を測定して Strength を取得します。\nZxcvbn zxcvbn = new Zxcvbn();\nStrength strength = zxcvbn.measure(\"This is password\");\n\n// 事前に用意したプロパティファイル(※)の名前とロケールを指定して、ResourceBundle を取得します。\nResourceBundle resourceBundle = ResourceBundle.getBundle(\"This is bundle name\", Locale.JAPAN);\n\n// FeedbackにResourceBundleを渡して、ローカライズされたFeedbackを生成します。\nFeedback feedback = strength.getFeedback();\nFeedback localizedFeedback = feedback.withResourceBundle(resourceBundle);\n\n// getSuggestions()、getWarning()で取得するフィードバックメッセージはローカライズ済みです。\nList\u003cString\u003e localizedSuggestions = localizedFeedback.getSuggestions();\nString localizedWarning = localizedFeedback.getWarning();\n```\n\nプロパティファイルに定義するキーとメッセージは、[messages.properties](https://github.com/nulab/zxcvbn4j/blob/master/src/main/resources/com/nulabinc/zxcvbn/messages.properties) を参考に作成してください。\n\n* http://www.opensource.org/licenses/mit-license.php\n\n#### リソースバンドルのセットを使ってローカライズする\n\n``` java\nStrength strength = zxcvbn.measure(password);\nFeedback feedback = strength.getFeedback();\n\nMap\u003cLocale, ResourceBundle\u003e messages = new HashMap\u003c\u003e();\nmessages.put(Locale.JAPANESE, ResourceBundle.getBundle(\"This is bundle name\", Locale.JAPANESE));\nmessages.put(Locale.ITALIAN, ResourceBundle.getBundle(\"This is bundle name\", Locale.ITALIAN));\nFeedback replacedFeedback = feedback.replaceResourceBundle(messages);\n```\n\n## 要件\n\n* Java 1.7以上\n\n## このライブラリを使用\n\n- [Backlog](https://backlog.com/)\n- [Cacoo](https://cacoo.com/)\n- [Typetalk](https://typetalk.com/)\n- [JetBrains Hub](https://www.jetbrains.com/hub/)\n- [Cryptomator](https://cryptomator.org/)\n- And many Open Source Software\n  - https://github.com/search?q=com.nulab-inc+zxcvbn\u0026type=code\n  - https://mvnrepository.com/artifact/com.nulab-inc/zxcvbn/usages\n\n## バグ報告やご意見\n\nバグ報告, ご意見、ご質問等は [Github Issues](https://github.com/nulab/zxcvbn4j/issues) にお願い致します。\n\n## ライセンス\n\nMIT License\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnulab%2Fzxcvbn4j","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnulab%2Fzxcvbn4j","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnulab%2Fzxcvbn4j/lists"}