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
2 changes: 0 additions & 2 deletions .github/workflows/deployment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,3 @@ jobs:
contents: read
pages: write
id-token: write
with:
docc_swift_version: "6.2"
8 changes: 1 addition & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,7 @@ Update the packages and you are ready.

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

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

> [!TIP]
> Avoid calling `database.execute` while in a transaction; use the transaction `connection` instead.

> [!WARNING]
> This repository is a work in progress, things can break until it reaches v1.0.0.
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.

## Usage example

Expand Down
14 changes: 4 additions & 10 deletions Sources/BCrypt/BCrypt.swift
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public final class BCrypt {
/// or ``BCryptError/hashFailure`` if hashing fails.
/// - Returns: A BCrypt hash string suitable for storage (e.g. in a database).
public func hash(
_ plaintext: String,
_ plaintext: String,
cost: Int = 12
) throws(BCryptError) -> String {
guard cost >= BCRYPT_MINLOGROUNDS && cost <= 31 else {
Expand All @@ -80,7 +80,7 @@ public final class BCrypt {
/// or ``BCryptError/hashFailure`` if hashing fails.
/// - Returns: A BCrypt hash string.
public func hash(
_ plaintext: String,
_ plaintext: String,
salt: String
) throws(BCryptError) -> String {
guard isSaltValid(salt) else {
Expand Down Expand Up @@ -150,7 +150,7 @@ public final class BCrypt {
/// or ``BcryptError/hashFailure`` if hashing fails during verification.
/// - Returns: `true` if `plaintext` matches the hash; otherwise `false`.
public func verify(
_ plaintext: String,
_ plaintext: String,
created hash: String
) throws(BCryptError) -> Bool {
guard let hashVersion = Algorithm(rawValue: String(hash.prefix(4)))
Expand Down Expand Up @@ -196,18 +196,12 @@ public final class BCrypt {
/// - algorithm: The BCrypt revision to use (defaults to `$2b$`).
/// - seed: Optional raw salt bytes. If `nil`, random bytes are generated. Must be 16 bytes when provided.
/// - Returns: A full salt string suitable to pass to ``hash(_:salt:)``.
private func generateSalt(
cost: Int,
algorithm: Algorithm = .b,
seed: [UInt8]? = nil
)
-> String
{
private func generateSalt(
cost: Int,
algorithm: Algorithm = .b,
seed: [UInt8]? = nil
) -> String {
let randomData: [UInt8]
if let seed = seed {
randomData = seed
}
Expand Down