Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .docctargetlist
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
BCrypt
1 change: 1 addition & 0 deletions .github/workflows/deployment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ on:
tags:
- 'v*'
- '[0-9]*'
workflow_dispatch:

jobs:

Expand Down
5 changes: 3 additions & 2 deletions .github/workflows/testing.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
format_check_enabled : true
broken_symlink_check_enabled : true
unacceptable_language_check_enabled : true
docs_check_enabled : true
docs_check_enabled : false
api_breakage_check_enabled : false
license_header_check_enabled : false
shell_check_enabled : false
Expand All @@ -27,6 +27,7 @@ jobs:
uses: BinaryBirds/github-workflows/.github/workflows/extra_soundness.yml@main
with:
local_swift_dependencies_check_enabled : true
headers_check_enabled : false
docc_warnings_check_enabled : true
run_tests_with_cache_enabled : true
headers_check_enabled : true
run_tests_swift_versions: '["6.1","6.2"]'
5 changes: 3 additions & 2 deletions .swiftheaderignore
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
Sources/CBCrypt/**
docker/**
.gitignore
.swift-format
.swiftformatignore
.swiftheaderignore
Sources/CBCrypt/**
.docctargetlist
.github/**
docker/**
AGENTS.md
LICENSE
Makefile
Expand Down
25 changes: 25 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# MIT License

Copyright (c) 2018-2022 Tibor Bödecs
Copyright (c) 2022-2026 Binary Birds Kft.

Permission is hereby granted, free of charge, to any person
obtaining a copy of this software and associated documentation
files (the "Software"), to deal in the Software without
restriction, including without limitation the rights to use,
copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following
conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.
7 changes: 5 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@ SHELL=/bin/bash

baseUrl = https://raw.githubusercontent.com/BinaryBirds/github-workflows/refs/heads/main/scripts

check: symlinks language deps lint headers
check: symlinks language deps lint headers docc-warnings package

package:
curl -s $(baseUrl)/check-swift-package.sh | bash

symlinks:
curl -s $(baseUrl)/check-broken-symlinks.sh | bash
Expand Down Expand Up @@ -38,4 +41,4 @@ test:
swift test --parallel

docker-test:
docker build -t feather-database-tests . -f ./docker/tests/Dockerfile && docker run --rm feather-database-tests
docker build -t tests . -f ./docker/tests/Dockerfile && docker run --rm tests
29 changes: 19 additions & 10 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,27 +24,36 @@ defaultSwiftSettings.append(
let package = Package(
name: "swift-bcrypt",
platforms: [
.macOS(.v13),
.iOS(.v16),
.tvOS(.v16),
.watchOS(.v9),
.visionOS(.v1),
.macOS(.v15),
.iOS(.v18),
.tvOS(.v18),
.watchOS(.v11),
.visionOS(.v2),
],
products: [
.library(name: "BCrypt", targets: ["BCrypt"]),
],
dependencies: [
// [docc-plugin-placeholder]
],
targets: [
.target(name: "CBCrypt"),
.target(name: "BCrypt", dependencies: [
.target(name: "CBCrypt"),
]),
.target(
name: "CBCrypt",
swiftSettings: defaultSwiftSettings
),
.target(
name: "BCrypt",
dependencies: [
.target(name: "CBCrypt"),
],
swiftSettings: defaultSwiftSettings
),
.testTarget(
name: "BCryptTests",
dependencies: [
.target(name: "BCrypt"),
]
],
swiftSettings: defaultSwiftSettings
),
]
)
50 changes: 23 additions & 27 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,29 +3,27 @@
Swift BCrypt implementation for securely hashing and verifying passwords using
adaptive cost factors, random salts, and constant-time comparison.

![Release: 2.0.0](https://img.shields.io/badge/Release-2%2E0%2E0-F05138)
[![Release: 2.0.1](https://img.shields.io/badge/Release-2.0.1-F05138)]( https://github.com/binarybirds/swift-bcrypt/releases/tag/2.0.1)

## Requirements

![Swift 6.1+](https://img.shields.io/badge/Swift-6%2E1%2B-F05138)
![Platforms: Linux, macOS, iOS, tvOS, watchOS, visionOS](https://img.shields.io/badge/Platforms-Linux_%7C_macOS_%7C_iOS_%7C_tvOS_%7C_watchOS_%7C_visionOS-F05138)

- Swift 6.1+
![Platforms: macOS, iOS, tvOS, watchOS, visionOS](https://img.shields.io/badge/Platforms-macOS_%7C_iOS_%7C_tvOS_%7C_watchOS_%7C_visionOS-F05138)

- Platforms:
- Linux
- macOS 15+
- iOS 18+
- tvOS 18+
- watchOS 11+
- visionOS 2+
- 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:

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

Then add `Bcrypt` to your target dependencies:
Expand All @@ -37,14 +35,12 @@ Then add `Bcrypt` to your target dependencies:
Update the packages and you are ready.

## Usage

![DocC API documentation](https://img.shields.io/badge/DocC-API_documentation-F05138)

API documentation is available at the following [link](https://binarybirds.github.io/swift-bcrypt). Refer to the mock objects in the Tests directory if you want to build a custom database driver implementation.
[![DocC API documentation](https://img.shields.io/badge/DocC-API_documentation-F05138)](https://binarybirds.github.io/swift-bcrypt)

## Usage example
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.

Basic example
## Usage example

```swift
import Bcrypt
Expand All @@ -53,21 +49,21 @@ let digest = try Bcrypt.hash("binary-birds", cost: 6)
let res = try Bcrypt.verify("binary-birds", created: digest)
```

## Credits

This code is derived from the Vapor web framework:

- [Vapor](https://github.com/vapor/vapor)

## Development

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

## Contributing

[Pull requests](https://github.com/binarybirds/swift-bcrypt/pulls) are welcome. Please keep changes focused and include tests for new logic. 🙏
[Pull requests](https://github.com/binarybirds/swift-bcrypt/pulls) are welcome. Please keep changes focused and include tests for new logic.

## Credits

This code is derived from the Vapor web framework:

- [Vapor](https://github.com/vapor/vapor)
4 changes: 2 additions & 2 deletions Sources/BCrypt/BCrypt.swift
Original file line number Diff line number Diff line change
Expand Up @@ -146,8 +146,8 @@ public final class BCrypt {
/// - Parameters:
/// - plaintext: The plaintext value to verify.
/// - hash: A BCrypt hash string previously produced by ``hash(_:cost:)`` or compatible implementations.
/// - Throws: ``BcryptError/invalidHash`` if the provided hash is malformed,
/// or ``BcryptError/hashFailure`` if hashing fails during verification.
/// - Throws: ``BCryptError/invalidHash`` if the provided hash is malformed,
/// or ``BCryptError/hashFailure`` if hashing fails during verification.
/// - Returns: `true` if `plaintext` matches the hash; otherwise `false`.
public func verify(
_ plaintext: String,
Expand Down