-
Notifications
You must be signed in to change notification settings - Fork 14
BCryptDigest
Creates and verifies BCrypt hashes. Normally you will not need to initialize one of these classes and you will
use the global BCrypt
convenience instead.
public final class BCryptDigest
try BCrypt.hash("vapor", cost: 4)
See BCrypt
for more information.
Creates a new BCryptDigest
. Use the global BCrypt
convenience variable.
public init()
Asynchronously hashes a password on a separate thread.
public func hashAsync(_ password: String) -> EventLoopFuture<String>
- password: The password to hash.
A future containing the hashed password that will resolve on the initiating EventLoop
.
Asynchronously verifies a password & hash on a separate thread.
public func verifyAsync(plaintext: String, hashed: String) -> EventLoopFuture<Bool>
- plaintext: The plaintext password.
- hashed: The hashed password to verify with.
A future containing a Bool
indicating whether the password and hash matched. This will resolve on the initiating EventLoop
.
public func hash(_ plaintext: String, cost: Int = 12) throws -> String
public func hash(_ plaintext: String, salt: String) throws -> String
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
.
public func verify(_ plaintext: String, created hash: String) throws -> Bool
let hash = try BCrypt.hash("vapor", cost: 4)
try BCrypt.verify("vapor", created: hash) // true
try BCrypt.verify("foo", created: hash) // false
- plaintext: Plaintext data to digest and verify.
- hash: Existing BCrypt hash to parse version, salt, and existing digest from.
CryptoError
if hashing fails or if data conversion fails.
true
if the hash was created from the supplied plaintext data.
Generated at 2021-01-13T22:24:59-0800 using swift-doc 1.0.0-beta.5.
Alchemy
Types
- AlterTableBuilder
- BCryptDigest
- BasicAuthMiddleware
- BcryptError
- BelongsToRelationship
- CORSMiddleware
- CORSMiddleware.AllowOriginSetting
- CORSMiddleware.Configuration
- ColumnType
- CreateColumn
- CreateColumnBuilder
- CreateIndex
- CreateTableBuilder
- DatabaseConfig
- DatabaseError
- DatabaseField
- DatabaseKeyMappingStrategy
- DatabaseValue
- DayUnit
- Env
- FrequencyTyped
- Grammar
- HTTPAuth
- HTTPAuth.Basic
- HTTPAuth.Bearer
- HTTPBody
- HTTPError
- HasManyRelationship
- HasOneRelationship
- HasRelationship
- HourUnit
- JoinClause
- JoinType
- Launch
- Log
- MIMEType
- MinuteUnit
- ModelQuery
- MySQLDatabase
- Operator
- OrderClause
- OrderClause.Sort
- OrderedDictionary
- PapyrusClientError
- PathParameter
- PathParameter.DecodingError
- PostgresDatabase
- Query
- Request
- Response
- Router
- RuneError
- SQL
- SQLJSON
- Scheduler
- Schema
- SecondUnit
- Services
- Socket
- StaticFileMiddleware
- StringLength
- Thread
- TokenAuthMiddleware
- WeekUnit
- Weekday
- WhereBoolean
- WhereColumn
- WhereIn
- WhereIn.InType
- WhereNested
- WhereRaw
- WhereValue