A native, dependency and Foundation free Swift implementation of the bcrypt password hashing algorithm, based on the OpenBSD implementation.
.package(url: "https://github.com/ptoffy/bcrypt.git", branch: "main").product(name: "Bcrypt", package: "bcrypt")import Bcrypt
let password = "password"
let hash = try Bcrypt.hash(password: password)
let isValid = try Bcrypt.verify(password: password, hash: hash)Currently these are the benchmarks for hashing the password "password" with cost factor 12, compared to Vapor's C Bcrypt implementation. Measurements were taken on an M2 MacBook Air.
| Release ms | Debug ms | Allocations Release | Allocations Debug | |
|---|---|---|---|---|
| vapor/authentication | 215ms | 337ms | ~13,700 | ~13,800 |
| bcrypt | 195ms | 453ms | ~13,400 | ~13,500 |