{"id":13518424,"url":"https://github.com/fnando/password_strength","last_synced_at":"2025-03-31T10:31:37.523Z","repository":{"id":831103,"uuid":"548348","full_name":"fnando/password_strength","owner":"fnando","description":"Check password strength against several rules. Includes ActiveRecord/ActiveModel support.","archived":true,"fork":false,"pushed_at":"2021-08-16T10:01:13.000Z","size":203,"stargazers_count":183,"open_issues_count":7,"forks_count":54,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-03-05T08:33:02.571Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/fnando.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2010-03-05T12:16:08.000Z","updated_at":"2023-10-13T08:17:45.000Z","dependencies_parsed_at":"2022-08-16T11:05:12.828Z","dependency_job_id":null,"html_url":"https://github.com/fnando/password_strength","commit_stats":null,"previous_names":[],"tags_count":21,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fnando%2Fpassword_strength","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fnando%2Fpassword_strength/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fnando%2Fpassword_strength/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fnando%2Fpassword_strength/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/fnando","download_url":"https://codeload.github.com/fnando/password_strength/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246453595,"owners_count":20779979,"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":[],"created_at":"2024-08-01T05:01:44.676Z","updated_at":"2025-03-31T10:31:37.271Z","avatar_url":"https://github.com/fnando.png","language":"JavaScript","funding_links":[],"categories":["JavaScript"],"sub_categories":[],"readme":"# Introduction\n\nCheck password strength against several rules. Includes ActiveRecord/ActiveModel support.\n\n\u003ca href=\"https://travis-ci.org/fnando/password_strength\"\u003e\u003cimg src=\"https://travis-ci.org/fnando/password_strength.svg\" alt=\"Build Status\" /\u003e\u003c/a\u003e\n\nValidates the strength of a password according to several rules:\n\n* size\n* 3+ numbers\n* 2+ special characters\n* uppercased and downcased letters\n* combination of numbers, letters and symbols\n* password contains username\n* sequences (123, abc, aaa)\n* repetitions\n* can't be a common password (view list at support/common.txt)\n\nSome results:\n\n* `123`: weak\n* `123abc`: weak\n* `aaaaaa`: weak\n* `myPass145`: good\n* `myPass145$`: strong\n\n## Install\n\n```\ngem install password_strength\n```\n\nor put this in your Gemfile:\n\n```ruby\ngem \"password_strength\"\n```\n\nThe JavaScript code is also available as a NPM package.\n\n```\nnpm install @fnando/password_strength --save\n```\n\nIf you want the source go to http://github.com/fnando/password_strength\n\n## Usage\n\n```ruby\nstrength = PasswordStrength.test(\"johndoe\", \"mypass\")\n#=\u003e return a object\n\nstrength.good?\n#=\u003e status == :good\n\nstrength.weak?\n#=\u003e status == :weak\n\nstrength.strong?\n#=\u003e status == :strong\n\nstrength.status\n#=\u003e can be :weak, :good, :strong\n\nstrength.valid?(:strong)\n#=\u003e strength == :strong\n\nstrength.valid?(:good)\n#=\u003e strength == :good or strength == :strong\n```\n\n## ActiveRecord/ActiveModel\n\nThe PasswordStrength library comes with ActiveRecord/ActiveModel support.\n\n```ruby\nclass Person \u003c ActiveRecord::Base\n  validates_strength_of :password\nend\n```\n\nTo be honest, you can use it with plain ActiveModel objects.\n\n```ruby\nclass Person\n  include ActiveModel::Model\n  validates_strength_of :password\nend\n\n# or simply\n\nclass Person\n  include ActiveModel::Validations\n  validates_strength_of :password\nend\n```\n\nThe default options are `:level =\u003e :good, :with =\u003e :username`.\n\nIf you want to compare your password against other field, you have to set the `:with` option.\n\n```ruby\nvalidates_strength_of :password, :with =\u003e :email\n```\n\nThe available levels are: `:weak`, `:good` and `:strong`.\n\n```ruby\nvalidates_strength_of :password, :with =\u003e :email, :level =\u003e :good\n```\n\nAlso you can set level with a lambda.\n\n```ruby\nvalidates_strength_of :password, :with =\u003e :email, :level =\u003e lambda {|u| :good }\n```\n\nYou can also provide a custom class/module that will test that password.\n\n```ruby\nvalidates_strength_of :password, :using =\u003e CustomPasswordTester\n```\n\nYour `CustomPasswordTester` class should override the default implementation. In practice, you're going to override only the `test` method that must call one of the following methods: `invalid!`, `weak!`, `good!` or `strong!`.\n\n```ruby\nclass CustomPasswordTester \u003c PasswordStrength::Base\n  def test\n    if password != \"mypass\"\n      invalid!\n    else\n      strong!\n    end\n  end\nend\n```\n\nThe tester above will accept only +mypass+ as password.\n\nPasswordStrength implements two validators: `PasswordStrength::Base` and `PasswordStrength::Validators::Windows2008`.\n\n**ATTENTION:** Custom validators are not supported by JavaScript yet!\n\n## JavaScript\n\nThe PasswordStrength also implements the algorithm in the JavaScript.\n\n```javascript\nvar strength = PasswordStrength.test(\"johndoe\", \"mypass\");\nstrength.isGood();\nstrength.isStrong();\nstrength.isWeak();\nstrength.isValid(\"good\");\n```\n\nThe API is basically the same!\n\nYou can use the `:exclude` option. Only regular expressions are supported for now.\n\n```javascript\nvar strength = PasswordStrength.test(\"johndoe\", \"password with whitespaces\", {exclude: /\\s/});\nstrength.isInvalid();\n```\n\nAdditionaly, a jQuery plugin is available.\n\n```javascript\n$.strength(\"#username\", \"#password\");\n```\n\nThe line above will validate the `#password` field against `#username`.\nThe result will be an image to the respective strength status. By default the image path will be\n`/images/weak.png`, `/images/good.png` and `/images/strong.png`.\n\nYou can overwrite the image path and the default callback.\n\n```javascript\n$.strength.weakImage = \"/weak.png\";\n$.strength.goodImage = \"/good.png\";\n$.strength.strongImage = \"/strong.png\";\n$.strength.callback = function(username, password, strength) {\n    // do whatever you want\n};\n```\n\nIf you just want to overwrite the callback, you can simple do\n\n```javascript\n$.strength(\"#username\", \"#password\", function(username, password, strength){\n    // do whatever you want\n});\n```\n\nGet the files:\n\n* https://github.com/fnando/password_strength/blob/master/app/assets/javascripts/jquery_strength.js\n* https://github.com/fnando/password_strength/blob/master/app/assets/javascripts/password_strength.js\n\nIf you're using asset pipeline, just add the following lines to your `application.js`.\n\n```javascript\n//= require jquery\n//= require password_strength\n//= require jquery_strength\n```\n\n## Running tests\n\n### Ruby\n\n1. Install all dependencies with `bundle install`.\n2. Run `rake test`.\n\n### JavaScript\n\n1. Install Node.js, then run `npm install`.\n2. Open `test/password_strength_test.html` in your target browser.\n\n## License\n\n(The MIT License)\n\nCopyright © 2010-2016 Nando Vieira (http://nandovieira.com)\n\nPermission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the ‘Software’), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED ‘AS IS’, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffnando%2Fpassword_strength","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffnando%2Fpassword_strength","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffnando%2Fpassword_strength/lists"}