{"id":15798416,"url":"https://github.com/chanced/p4ssw0rd","last_synced_at":"2025-03-31T20:12:39.750Z","repository":{"id":57571043,"uuid":"347175275","full_name":"chanced/p4ssw0rd","owner":"chanced","description":"Go password strength validation utilizing the haveibeenpwned API","archived":false,"fork":false,"pushed_at":"2021-05-27T17:54:26.000Z","size":47,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2024-10-06T00:41:16.479Z","etag":null,"topics":["go","golang","password","pwned-passwords","validation"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/chanced.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2021-03-12T19:24:48.000Z","updated_at":"2022-12-21T15:52:14.000Z","dependencies_parsed_at":"2022-09-17T15:42:53.523Z","dependency_job_id":null,"html_url":"https://github.com/chanced/p4ssw0rd","commit_stats":null,"previous_names":[],"tags_count":11,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chanced%2Fp4ssw0rd","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chanced%2Fp4ssw0rd/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chanced%2Fp4ssw0rd/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chanced%2Fp4ssw0rd/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/chanced","download_url":"https://codeload.github.com/chanced/p4ssw0rd/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246531975,"owners_count":20792736,"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":["go","golang","password","pwned-passwords","validation"],"created_at":"2024-10-05T00:41:24.889Z","updated_at":"2025-03-31T20:12:39.727Z","avatar_url":"https://github.com/chanced.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# p4ssw0rd\n\nGo password strength validation utilizing the [have i been pwned?](https://haveibeenpwned.com/API/v3#SearchingPwnedPasswordsByRange) API. Make sure you read and abide by their [license](https://haveibeenpwned.com/API/v3#License)\n\n## Usage\n\n```bash\ngo get github.com/chanced/p4ssw0rd\n```\n\n```go\npackage main\n\nimport(\n    \"context\"\n    \"errors\"\n\n    \"github.com/chanced/p4ssw0rd\"\n)\n\nfunc main() {\n    ctx := context.Background()\n    pw, err := p4ssw0rd.New(p4ssw0rd.Config{\n        UserAgent:               \"your site\", // required\n        MinPasswordLength:       6,           // default: 6\n        BreachLimit:             10,          // default: 10\n        MaxPwnedRequestAttempts: 3,           // default: 3\n        AddPadding:              false,       // default: false\n    })\n    if err != nil {\n        // The only reason this would happen is if you didn't provide a user agent.\n        // see https://haveibeenpwned.com/API/v3#UserAgent\n        panic(err)\n    }\n\n    eval, err := pw.Evaluate(ctx, \"password\")\n    if err != nil {\n        // this shouldn't error unless something goes wrong with connecting to haveibeenpwned because\n        // \"password\" satisfies the min length requirement\n        panic(err)\n    }\n    _ = eval.Allowed // false because the count of breaches this value has been involved in exceeds BreachLimit\n    _ = eval.BreachCount // 3861493 as of running this\n    _ = eval.Notes // \"\"; it will remain blank for now. Add your own notes in your handler\n\n    eval, err = pw.Evaluate(ctx, \"pass\")\n    if err != nil {\n        // err is a p4ssw0rd.MinLengthError because len(\"pass\") \u003c pw.MinPasswordLength\n        var mlerr *p4ssw0rd.MinLengthError\n        if errors.As(err, \u0026mlerr) {\n            _ = err.MinRequired // 6, as set by pw.MinPasswordLength\n            _ = err.Length // 4\n        } else {\n            //connection issues with haveibeenpwned\n            panic(err)\n        }\n    }\n    err = pw.Validate(ctx, \"password\")\n    if err != nil {\n        var blerr *p4ssw0rd.BreachLimitError\n        if errors.As(err, \u0026blerr) {\n            _ = blerr.BreachCount\n        }\n    }\n}\n```\n\n## Explanation\n\nThe way the package works is the password is hashed (SHA1) then the first 5 characters of that are used to query the API. The result set contains the remainder of the hash, if the password is present, and the count of breaches it has been discovered in. The results from have i been pwned look like this:\n\n```\n1E2AAA439972480CEC7F16C795BBB429372:1\n1E3687A61BFCE35F69B7408158101C8E414:1\n1E4C9B93F3F0682250B6CF8331B7EE68FD8:3861493\n00306FB8A6E528F9B377D068C625E2D5B55:2\n00415E48D704BA89B118934A33E202E41F9:1\n00DFA98B45FE3EE9D2F7BF6872E37672D03:2\n012562CD2D1BECE861B1566A974B52ACBF9:1\n012BE47C832BEE70CAA8E89364FF59B09EA:1\n0134585DCB1B38E99BD0CDA7E56D42A0C16:1\n01D41F17FC9C9CF616DE7A6BA237929AC91:1\n01ED16B974AE0010799BF0AE6F77E8F6CC5:10\n01FFD148305A472EBCED1BF4E70089A0532:1\n```\n\nIf you're still concerned about a man in the middle snooping responses, you can turn on padding which ensures that there are consistently 800 - 1,000 results. See https://haveibeenpwned.com/API/v3#PwnedPasswordsPadding\n\n## Documentation\n\nhttps://pkg.go.dev/github.com/chanced/p4ssw0rd\n\n## License\n\np4ssw0rd is licensed under the Apache License, Version 2.0. See [LICENSE](https://github.com/chanced/p4ssw0rd/blob/main/LICENSE) for the full license text.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fchanced%2Fp4ssw0rd","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fchanced%2Fp4ssw0rd","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fchanced%2Fp4ssw0rd/lists"}