{"id":16250837,"url":"https://github.com/arithefirst/postgres-credential-storage","last_synced_at":"2026-05-02T04:34:00.877Z","repository":{"id":257814495,"uuid":"868635362","full_name":"arithefirst/postgres-credential-storage","owner":"arithefirst","description":"A system for storing salted and hashed user credentials in PostgreSQL implemented in go","archived":false,"fork":false,"pushed_at":"2024-10-06T21:57:35.000Z","size":8,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-01T20:06:19.163Z","etag":null,"topics":["golang","golang-library","golang-package","hash","password","postgres","salting","sha256"],"latest_commit_sha":null,"homepage":"","language":"Go","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/arithefirst.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-10-06T21:57:11.000Z","updated_at":"2024-10-06T22:02:40.000Z","dependencies_parsed_at":"2024-10-09T00:25:19.028Z","dependency_job_id":null,"html_url":"https://github.com/arithefirst/postgres-credential-storage","commit_stats":null,"previous_names":["arithefirst/postgres-credential-storage"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/arithefirst%2Fpostgres-credential-storage","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/arithefirst%2Fpostgres-credential-storage/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/arithefirst%2Fpostgres-credential-storage/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/arithefirst%2Fpostgres-credential-storage/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/arithefirst","download_url":"https://codeload.github.com/arithefirst/postgres-credential-storage/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247840951,"owners_count":21005015,"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":["golang","golang-library","golang-package","hash","password","postgres","salting","sha256"],"created_at":"2024-10-10T15:06:50.053Z","updated_at":"2026-05-02T04:34:00.851Z","avatar_url":"https://github.com/arithefirst.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Postgres Credential Storage\nA simple system to store user credentials in postgres utilizing salts and SHA256, \nimplemented in go. Created by [arithefirst](https://arithefirst.com).\n# Docs\n## Prerequisites\nIn order to use this library, you must have a table in your database with the properties shown\u003cbr\u003e \nbelow. If your table does not have these properties, or is not named `login`, this library will\u003cbr\u003e\nnot work. Your table can have more columns than show, but must have these 3 at least.\n```SQL\nCREATE TABLE login (\n    username text unique,\n    salt text,\n    hash text\n)\n```\n\n## Connecting to your DB\nIn order to connect to your DB, you need to create a variable or const of type\u003cbr\u003e\n`pcs.PostgresConnection`. You can then populate this variable with the connection\u003cbr\u003e\ndetails for your PostgreSQL server.\n\n```golang\npackage main\nimport pcs \"github.com/arithefirst/postgres-credential-storage\"\n\nfunc main() {\n\tconnection := pcs.PostgresConnection{\n\t\tHost: \"localhost\",\n\t\tPort: 5432,\n\t\tUser: \"postgres\",\n\t\tPass: \"postgres\",\n\t\tDb:   \"users\",\n\t\tSSL:  false,\n\t}\n}\n```\n\n## Hashing and Salting plaintext credentials\nPCS Comes with a function to Hash and Salt your credentials for you from plaintext.\u003cbr\u003e \nJust run the `pcs.SetPassword()` function with the required parameters, and it will\u003cbr\u003e\nstore the password's salt and hash in the DB. All you need to pass in is your variable \u003cbr\u003e\nof type `pcs.PostgresConnection`, username, and password. The password is then \u003cbr\u003e\nsalted, SHA256 Hashed, and added to the DB.\n\n```golang\nfunc main() {\n\terr := pcs.SetPassword(\"johnsmith@example.com\", \"password123\", connection)\n\tif err != nil {\n\t\tpanic(err)\n\t}\n}\n```\nOutput:\n```\n+-----------------------+----------------------------------+------------------------------------------------------------------+\n| username              | salt                             | hash                                                             |\n+-----------------------+----------------------------------+------------------------------------------------------------------+\n| johnsmith@example.com | ^5@gVJN8\u003e5p$67qXku2b6Oe6!#Z7Bd5c | 8993f6ad6e8539c0382ef40b3a320501d561d8e8eeceaaaeb59efcea6b7083b1 |\n+-----------------------+----------------------------------+------------------------------------------------------------------+\n```\n\n## Storing pre-encrypted credentials\nIf you need to store a password that has already been salted and hashed, you can run \u003cbr\u003e\n`pcs.setPasswordNoHash` with the connection variable, plaintext salt, and the SHA256 hash.\n```golang\nfunc main() {\n\terr := pcs.SetPasswordNoHash(\"johnsmith@example.com\",\n\t\t\"8993f6ad6e8539c0382ef40b3a320501d561d8e8eeceaaaeb59efcea6b7083b1\",\n\t\t\"^5@gVJN8\u003e5p$67qXku2b6Oe6!#Z7Bd5c\", connection)\n\tif err != nil {\n\t\tpanic(err)\n\t}\n}\n```\nOutput:\n```\n+-----------------------+----------------------------------+------------------------------------------------------------------+\n| username              | salt                             | hash                                                             |\n+-----------------------+----------------------------------+------------------------------------------------------------------+\n| johnsmith@example.com | ^5@gVJN8\u003e5p$67qXku2b6Oe6!#Z7Bd5c | 8993f6ad6e8539c0382ef40b3a320501d561d8e8eeceaaaeb59efcea6b7083b1 |\n+-----------------------+----------------------------------+------------------------------------------------------------------+\n```\n\n## Validating Credentials\nTo check if a password for a given user is valid, use `pcs.CheckPassword`. It requires a user\u003cbr\u003e\nand the password you want to validate. It will pull the salt and hash from the database for the\u003cbr\u003e\nspecified user, salt the given password, and check if the hashes match. If they do match, it will\u003cbr\u003e\nreturn `(true, nil)`. otherwise it will return `(false, nil)`.\n```golang\nfunc main() {\n    // Returns true, nil \n    valid, err := pcs.CheckPassword(\"johnsmith@example.com\", \"password123\")\n    if err != nil{\n        panic(err)\n    }\n\t\n    // Returns false, nil\n    valid, err := pcs.CheckPassword(\"johnsmith@example.com\", \"notpassword123\")\n    if err != nil{\n        panic(err)\n    }\n} \n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Farithefirst%2Fpostgres-credential-storage","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Farithefirst%2Fpostgres-credential-storage","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Farithefirst%2Fpostgres-credential-storage/lists"}