Skip to content
A bcrypt library for NodeJS.
Scala
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
project
src
.gitignore
LICENSE
README.md
build.sbt
package.json

README.md

Bcrypt API for Scala.js

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

Build/publish the SDK locally

 $ sbt clean publish-local

Running the tests

Before running the tests the first time, you must ensure the npm packages are installed:

$ npm install

Then you can run the tests:

$ sbt test

Examples

Using Bcrypt asynchronously via callbacks

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

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

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:

libraryDependencies += "io.scalajs.npm" %%% "bcrypt" % "0.5.0"

Optionally, you may add the Sonatype Repository resolver:

resolvers += Resolver.sonatypeRepo("releases") 
You can’t perform that action at this time.