Skip to content

Enumeration

VaporBcrypt

Creates and verifies bcrypt hashes.
enum VaporBcrypt

Overview

Use BcryptDigest to create hashes for sensitive information like passwords.

try BcryptDigest.hash("vapor", cost: 12)

bcrypt uses a random salt each time it creates a hash. To verify hashes, use the verify(_:matches) method.

let hash = try BcryptDigest.hash("vapor", cost: 12)
try BcryptDigest.verify("vapor", created: hash) // true

https://en.wikipedia.org/wiki/bcrypt

Topics

Type Methods

  • hash(_:cost:)
    Creates a new bcrypt hash with a randomly generated salt. The result can be stored in a database. parameters: - plaintext: Plaintext data to hash. - cost: Desired complexity. Larger cost values take longer to hash and verify. Default is 12.
  • hash(_:salt:)
    Creates a bcrypt hash using a provided salt.
  • verify(_:created:)
    Verifies an existing bcrypt hash matches the supplied plaintext value. Verification works by parsing the salt and version from the existing digest and using that information to hash the plaintext data. If hash digests match, this method returns true.

Relationships

Conforms To

  • Swift.Sendable
  • Swift.SendableMetatype