Skip to content

Type Method

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.
static func verify(_ plaintext: String, created hash: String) throws(BcryptError) -> Bool

Parameters

plaintext

Plaintext data to digest and verify.

hash

Existing bcrypt hash to parse version, salt, and existing digest from.

Return Value

true if the hash was created from the supplied plaintext data.

Discussion

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

Throws

BcryptError if hashing fails or if data conversion fails.