{"id":42640361,"url":"https://github.com/pkg-id/passwd","last_synced_at":"2026-01-29T06:13:03.827Z","repository":{"id":137358211,"uuid":"611688513","full_name":"pkg-id/passwd","owner":"pkg-id","description":"passwd is a zero-setup package for hashing passwords and comparing passwords.","archived":false,"fork":false,"pushed_at":"2023-03-26T17:31:21.000Z","size":14,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2024-06-20T08:00:15.278Z","etag":null,"topics":["bcrypt","go","hash","sql"],"latest_commit_sha":null,"homepage":"","language":"Go","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/pkg-id.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-03-09T10:44:58.000Z","updated_at":"2023-06-15T22:18:29.000Z","dependencies_parsed_at":null,"dependency_job_id":"1bfe32db-4499-4047-8101-ac65da5f59bb","html_url":"https://github.com/pkg-id/passwd","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/pkg-id/passwd","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pkg-id%2Fpasswd","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pkg-id%2Fpasswd/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pkg-id%2Fpasswd/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pkg-id%2Fpasswd/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/pkg-id","download_url":"https://codeload.github.com/pkg-id/passwd/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pkg-id%2Fpasswd/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28865615,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-29T05:56:06.453Z","status":"ssl_error","status_checked_at":"2026-01-29T05:55:57.668Z","response_time":59,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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":["bcrypt","go","hash","sql"],"created_at":"2026-01-29T06:13:03.189Z","updated_at":"2026-01-29T06:13:03.820Z","avatar_url":"https://github.com/pkg-id.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# passwd\n\n[![GoDoc](https://godoc.org/github.com/pkg-id/passwd?status.svg)](https://godoc.org/github.com/pkg-id/passwd)\n[![Go Report Card](https://goreportcard.com/badge/github.com/pkg-id/passwd)](https://goreportcard.com/report/github.com/pkg-id/passwd)\n[![License](https://img.shields.io/badge/license-MIT-blue.svg)](https://raw.githubusercontent.com/pkg-id/passwd/master/LICENSE)\n\npasswd is a zero-setup package for hashing passwords and comparing passwords. This package makes it easy to use `passwd.Password` just like a normal string, but it is secure.\n\n## Features\n\n- Zero-setup, just use `passwd.Password` like a normal string, and it will be hashed automatically when storing to the database.\n- Implements sql.Scanner and driver.Valuer interfaces.\n- Hide the password when printing and Marshaling to JSON.\n- Customizable hash comparer algorithm.\n\n## Installation\n\n```bash\ngo get github.com/pkg-id/passwd\n```\n\n## Usage\n\nHere's an example of how to use passwd with a PostgreSQL database:\n\n```go\npackage main\n\nimport (\n\t\"database/sql\"\n\t\"fmt\"\n\t\"log\"\n\n\t\"github.com/pkg-id/passwd\"\n\t\"github.com/pkg-id/passwd/bcrypt\"\n\n\t_ \"github.com/lib/pq\"\n)\n\nfunc main() {\n\t// Open a connection to the database.\n\tdb, err := sql.Open(\"postgres\", \"user=postgres password=postgres dbname=mydb sslmode=disable\")\n\tif err != nil {\n\t\tlog.Fatalf(\"open db. error: %v\", err)\n\t}\n\tdefer db.Close()\n\n\t// OPTIONAL: Set the hash comparer to bcrypt.\n\tpasswd.SetHashComparer(bcrypt.DefaultCost)\n\n\t// Hash the password.\n\tplain := \"pass1234\"\n\tpwd := passwd.Password(plain)\n\n\t// Insert the password into the database.\n\tconst insert = \"INSERT INTO users(password) VALUES ($1) RETURNING id;\"\n\tvar id int64\n\terr = db.QueryRow(insert, pwd).Scan(\u0026id)\n\tif err != nil {\n\t\tlog.Fatalf(\"query row. error: %v\", err)\n\t}\n\n\t// Retrieve the password from the database.\n\tconst query = \"SELECT password FROM users WHERE id = $1;\"\n\tvar scanned passwd.Password\n\terr = db.QueryRow(query, id).Scan(\u0026scanned)\n\tif err != nil {\n\t\tlog.Fatalf(\"scan row. error: %v\", err)\n\t}\n\n\t// Compare the password.\n\terr = scanned.Compare(plain)\n\tif err != nil {\n\t\tlog.Fatalf(\"expect password match\")\n\t}\n\n\terr = scanned.Compare(\"must be not match\")\n\tif err == nil {\n\t\tlog.Fatalf(\"expect password not match\")\n\t}\n}\n```\n\n\u003e The `passwd.SetHashComparer` function is optional, since bcrypt is already used as the default hash comparer. However, it can be used to set a different hash comparer if needed.\n\n### How it works\n\n`passwd.Password` is a new type based on the string type, and it is used to represent a password. When a password is stored, it is hashed using the default hash comparer (`bcrypt`). When a password is retrieved from the database, it is compared to the plain text password using the same hash comparer. If the passwords match, no error is returned. If the passwords do not match, an error is returned.\n\n\n## License\n\nThis project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpkg-id%2Fpasswd","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpkg-id%2Fpasswd","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpkg-id%2Fpasswd/lists"}