0.1.0 • Published 2 years ago

bcrypt-rsjs v0.1.0

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

bcrypt-rsjs

created by Austin Poor

A bcrypt library for Node.js, written in Rust and Neon - designed to replace bcrypt, which uses C++.

Example

const bcrypt = require('bcrypt-rsjs');

const my_password = 'Passw0rd';
const not_my_password = 'tell everyone';

// Hash a password
await bcrypt.hash(my_password);
// $2b$12$MF80o/X4kYVqS4psVu/eKO46fFm5hk6nhqwEykw/joHmR3A0DBX4q

// Hash a password with a custom cost
await bcrypt.hash(my_password, 8);
// $2b$08$zMIjSo9Gd62jtXlHR4eCkullNag4WFpK798jrpytD8Mb/dbW75Nk.

// Validate a password
await bcrypt.compare(my_password, hash);
// true

// Validate a password
await bcrypt.compare(not_my_password, hash);
// false

Benchmarks

Benchmarks were run for bcrypt-rsjs (this library), bcrypt (uses C++), and bcryptjs (which is pure js).

Based on the results below, bcrypt-rsjs has comparable performance to the C++ library. Tests can be rerun via npm run bench.

Sync Hash Benchmark

Runs n hashes in sequential order.

namefunccostn teststime (ms)time/hash (ms)
bcrypthashSync81,00012,061.8612.06
bcryptjshashSync81,00016,220.7816.22
bcrypt-rsjshashSync81,00012,717.0012.72
bcrypthashSync1210019,437.58194.38
bcryptjshashSync1210025,373.67253.74
bcrypt-rsjshashSync1210019,902.50199.03
bcrypthashSync161030,637.603,063.76
bcryptjshashSync161039,685.473,968.55
bcrypt-rsjshashSync161031,941.443,194.14

Async Hash Benchmark

Runs n hashes simultaneously, via Promise.all(hashes).

namefunccostn teststime (ms)time/hash (ms)
bcrypthash81,0003,283.853.28
bcryptjshash81,00015,711.4815.71
bcrypt-rsjshash81,0003,316.773.32
bcrypthash121005,126.8251.27
bcryptjshash1210024,846.76248.47
bcrypt-rsjshash121005,245.1152.45
bcrypthash16109733.09973.31
bcryptjshash161039,921.913,992.19
bcrypt-rsjshash16109,994.12999.41