Skip to content

Swift BCrypt implementation for securely hashing and verifying passwords using adaptive cost factors, random salts, and constant-time comparison.

License

Notifications You must be signed in to change notification settings

BinaryBirds/swift-bcrypt

Repository files navigation

Swift BCrypt

Swift BCrypt implementation for securely hashing and verifying passwords using adaptive cost factors, random salts, and constant-time comparison.

Release: 2.0.1

Requirements

Swift 6.1+ Platforms: macOS, iOS, tvOS, watchOS, visionOS

  • Swift 6.1+
  • Platforms:
    • macOS 15+
    • iOS 18+
    • tvOS 18+
    • watchOS 11+
    • visionOS 2+

Installation

Use Swift Package Manager; add the dependency to your Package.swift file:

.package(url: "https://github.com/binarybirds/swift-bcrypt", exact: "2.0.1"),

Then add Bcrypt to your target dependencies:

.product(name: "Bcrypt", package: "swift-bcrypt"),

Update the packages and you are ready.

Usage

DocC API documentation

API documentation is available at the following link. Refer to the mock objects in the Tests directory if you want to build a custom database driver implementation.

Usage example

import Bcrypt

let digest = try Bcrypt.hash("binary-birds", cost: 6)
let res = try Bcrypt.verify("binary-birds", created: digest)

Development

  • Build: swift build
  • Test:
    • local: swift test
    • using Docker: make docker-test
  • Format: make format
  • Check: make check

Contributing

Pull requests are welcome. Please keep changes focused and include tests for new logic.

Credits

This code is derived from the Vapor web framework:

About

Swift BCrypt implementation for securely hashing and verifying passwords using adaptive cost factors, random salts, and constant-time comparison.

Resources

License

Stars

Watchers

Forks

Contributors 4

  •  
  •  
  •  
  •