https://github.com/scalajs-io/bcrypt
A bcrypt library for NodeJS.
https://github.com/scalajs-io/bcrypt
bcrypt bcrypt-library node nodejs npm npm-package scala scalajs
Last synced: 4 months ago
JSON representation
A bcrypt library for NodeJS.
- Host: GitHub
- URL: https://github.com/scalajs-io/bcrypt
- Owner: scalajs-io
- License: apache-2.0
- Created: 2017-02-05T04:22:33.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2020-08-20T15:03:20.000Z (almost 5 years ago)
- Last Synced: 2025-01-17T22:42:44.283Z (5 months ago)
- Topics: bcrypt, bcrypt-library, node, nodejs, npm, npm-package, scala, scalajs
- Language: Scala
- Size: 21.5 KB
- Stars: 0
- Watchers: 4
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
Bcrypt API for Scala.js
================================
[bcrypt](https://www.npmjs.com/package/bcrypt) - A bcrypt library for NodeJS.### Description
`bcrypt` is a password hashing function designed by Niels Provos and David Mazières,
based on the Blowfish cipher, and presented at USENIX in 1999.### Build Dependencies
* [SBT v1.2.x](http://www.scala-sbt.org/download.html)
### Build/publish the SDK locally
```bash
$ sbt clean publish-local
```### Running the tests
Before running the tests the first time, you must ensure the npm packages are installed:
```bash
$ npm install
```Then you can run the tests:
```bash
$ sbt test
```### Examples
Using `Bcrypt` asynchronously via callbacks
```scala
import io.scalajs.npm.bcrypt._val saltRounds = 13
val myPlaintextPassword = "b@c0n"Bcrypt.hash(myPlaintextPassword, saltRounds, (_, hash) => {
Bcrypt.compare(myPlaintextPassword, hash, (_, isMatch) => {
println(s"The password was a match: $isMatch") // The password was a match: true
})
})
```Using `Bcrypt` asynchronously via promises
```scala
import io.scalajs.npm.bcrypt._val saltRounds = 13
val myPlaintextPassword = "b@c0n"for {
hash <- Bcrypt.hash(myPlaintextPassword, saltRounds)
isMatch <- Bcrypt.compare(myPlaintextPassword, hash)
} {
println(s"The password was a match: $isMatch") // The password was a match: true
}
```Using `Bcrypt` synchronously
```scala
import io.scalajs.npm.bcrypt._val saltRounds = 13
val myPlaintextPassword = "b@c0n"val hash = Bcrypt.hashSync(myPlaintextPassword, saltRounds)
val isMatch = Bcrypt.compareSync(myPlaintextPassword, hash)
println(s"The password was a match: $isMatch") // The password was a match: true
```### Artifacts and Resolvers
To add the `Bcrypt` binding to your project, add the following to your build.sbt:
```sbt
libraryDependencies += "io.scalajs.npm" %%% "bcrypt" % "0.5.0"
```Optionally, you may add the Sonatype Repository resolver:
```sbt
resolvers += Resolver.sonatypeRepo("releases")
```