{"id":17159144,"url":"https://github.com/scull7/bs-password","last_synced_at":"2025-03-24T14:45:15.903Z","repository":{"id":142121179,"uuid":"135422983","full_name":"scull7/bs-password","owner":"scull7","description":"A password hashing library for ReasonML","archived":false,"fork":false,"pushed_at":"2018-11-17T05:40:18.000Z","size":408,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-02T10:16:49.357Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://scull7.github.io/bs-password/","language":"OCaml","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/scull7.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":"2018-05-30T09:52:06.000Z","updated_at":"2018-11-17T05:40:19.000Z","dependencies_parsed_at":null,"dependency_job_id":"7f9525d2-2a6d-4462-ba57-b951d5c2e56b","html_url":"https://github.com/scull7/bs-password","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/scull7%2Fbs-password","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/scull7%2Fbs-password/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/scull7%2Fbs-password/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/scull7%2Fbs-password/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/scull7","download_url":"https://codeload.github.com/scull7/bs-password/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245294711,"owners_count":20591898,"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-10-14T22:13:27.848Z","updated_at":"2025-03-24T14:45:15.880Z","avatar_url":"https://github.com/scull7.png","language":"OCaml","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![Build Status](https://travis-ci.com/scull7/bs-password.svg?branch=master)](https://travis-ci.com/scull7/bs-password)\n[![Coverage Status](https://coveralls.io/repos/github/scull7/bs-password/badge.svg?branch=master)](https://coveralls.io/github/scull7/bs-password?branch=master)\n\n# bs-password\n\nA password hashing libarary for ReasonML\n\n## How do I install it?\n\nInside of a BuckleScript project:\n\n```sh\nyarn add bs-password\n```\n\nThen add `bs-password` to your `bs-dependencies` in `bsconfig.json`\n\n```json\n{\n  \"bs-dependencies\": [ \"bs-password\" ]\n}\n```\n\n## Usage\n\n### Basic Callback based interface.\n\n1. Derive a hash\n\n```reason\nlet password = \"This is my password\";\nlet algorithm = Password.Algorithm.Bcrypt;\n\nPassword.deriveKey(algorithm, password, (result) =\u003e {\n  switch (result) {\n  | Belt.Result.Error(e) =\u003e raise(e)\n  | Belt.Result.Ok((salt, hash)) =\u003e Js.log3(\"Salt and Key\", salt, hash)\n  };\n});\n```\n\n2. Verify a hash against a password.\n\n```reason\nlet password = \"This is my passsword\";\nlet algorithm = Password.Algorithm.Bcrypt;\n\nPassword.deriveKey(algorithm, password, (result) =\u003e {\n  switch (result) {\n  | Belt.Result.Error(e) =\u003e raise(e)\n  | Belt.Result.Ok((_, hash)) =\u003e\n    Password.verify(algorithm, hash, password, (result2) =\u003e {\n    switch (result) {\n    | Belt.Result.Error(e) =\u003e raise(e)\n    | Belt.Result.Ok(isValid) =\u003e Js.log2(\"isValid: \", isValid)\n    }\n    });\n  };\n});\n```\n\n3. Generate a random token.\n\n```reason\nlet algorithm = Password.Algorithm.Bcrypt;\nlet length = 8;\n\nPassword.token(algorithm, length, (result) =\u003e {\n  switch(result) {\n  | Belt.Result.Error(e) =\u003e raise(e)\n  | Belt.Result.Ok(token) =\u003e Js.log2(\"Token: \", token)\n  };\n});\n```\n\n### [Future][reason-future] based interface.\n\n1. Derive a hash.\n\n```reason\nlet password = \"This is my password\";\nlet algorithm = Password.Algorithm.Bcrypt;\n\nPassword.Future.deriveKey(algorithm, password)\n|. Future.mapOk(((salt, hash)) =\u003e Js.log3(\"Salt and Key: \", salt, hash))\n|. Future.mapError(raise);\n```\n\n2. Verify a hash against a password.\n\n```reason\nlet password = \"This is my password\";\nlet algo = Password.Algorithm.Bcrypt;\n\nPassword.Future.deriveKey(algo, password)\n|. Future.flatMapOk(((_, hash)) =\u003e Password.Future.verify(algo, hash, password))\n|. Future.mapOk(isValid =\u003e Js.log2(\"Is Valid: \", isValid))\n|. Future.mapError(raise)\n```\n\n3. Generate a random token.\n\n```reason\nlet algo = Password.Algorithm.Bcrypt;\n\nPassword.Future.token(algo, 16)\n|. Future.mapOk(token =\u003e Js.log2(\"Token: \", token))\n|. Future.mapError(raise)\n```\n\n### Promise based interface.\n\n1. Derive a hash.\n\n```reason\nlet password = \"This is my password\";\nlet algorithm = Password.Algorithm.Bcrypt;\n\nPassword.Promise.deriveKey(algorithm, password)\n|\u003e Js.Promise.then_(result =\u003e\n  switch (result) {\n  | Belt.Result.Error(e) =\u003e raise(e)\n  | Belt.Result.Ok((salt, hash)) =\u003e Js.log3(\"Salt and key: \", salt, hash)\n  }\n  |\u003e Js.Promise.resolve\n)\n```\n\n2. Verify a hash against a password.\n\n```reason\nlet password = \"This is my password\";\nlet algo = Password.Algorithm.Bcrypt;\n\nPassword.Promise.deriveKey(algo, password)\n|\u003e Js.Promise.then_(result =\u003e\n  switch (result) {\n  | Belt.Result.Error(e) =\u003e raise(e)\n  | Belt.Result.Ok((_, hash)) =\u003e Js.Promise.resolve(hash)\n  }\n)\n|\u003e Js.Promise.then_(hash =\u003e Password.Promise.verify(algo, hash, password))\n|\u003e Js.Promise.then_(isValid =\u003e\n  Js.log2(\"Does Match: \", isValid) |\u003e Js.Promise.resolve\n) \n```\n\n3. Generate a random token.\n\n```reason\nlet algo = Password.Algorithm.Bcrypt;\n\nPassword.Promise.token(algo, 31)\n|\u003e Js.Promise.then_(token =\u003e Js.log2(\"Token: \", token) |\u003e Js.Promise.resolve)\n```\n\n\n[reason-future]: https://github.com/RationalJS/future\n[Js.Promise]: https://bucklescript.github.io/bucklescript/api/Js.Promise.html\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fscull7%2Fbs-password","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fscull7%2Fbs-password","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fscull7%2Fbs-password/lists"}