This is a port from jBCrypt to TypeScript for use in Deno.
It has zero third-party dependencies.
Running in sync requires no permissions. Running in async functionality requires --allow-net and --unstable
If you don't want to specify a specific version and are happy to work with breaking changes, you can import this module like so:
import * as bcrypt from "https://deno.land/x/bcrypt/mod.ts";
To ensure that you've got a specific version, it's recommend to import this module specifying a specific release like so:
import * as bcrypt from "https://deno.land/x/bcrypt@v0.2.4/mod.ts";
The Async implementation requires WebWorkers which require --allow-net to import Deno standard modules from inside the Worker. Also, to allow Crypto inside a WebWorker, you'll need to use the --unstable flag too.
const hash = await bcrypt.hash("test");
To check a password:
const result = await bcrypt.compare("test", hash);
To hash a password with a manually generated salt:
const salt = await bcrypt.genSalt(8);
const hash = await bcrypt.hash("test", salt);
It is not recommended to use this unless you're running a quick script since the BCrypt algorithm is computationally quite expensive. For example, if you're running a server and make multiple calls to it, other requests will be blocked. Using the Async methods are recommended.
To hash a password (with auto-generated salt):
const hash = bcrypt.hashSync("test");
To check a password:
const result = bcrypt.compareSync("test", hash);
To hash a password with a manually generated salt:
const salt = bcrypt.genSaltSync(8);
const hash = bcrypt.hashSync("test", salt);
For any bug reports or feature requests, please create an issue on GitHub.