Argon2 Provider for Vapor 2.x
This package allows you to integrate the Argon2 password hash with Vapor applications.
Installation
- Add the following dependency to your Package.swift:
.Package(url: "https://github.com/vzsg/vapor-argon2-provider.git", majorVersion: 0, minor: 1)
- Call
swift package update
andswift package generate-xcodeproj
. - Register the provider with your Config instance. In the Vapor templates, this is done in
Config+Setup.swift
:import Argon2Provider extension Config { ... func addProviders() throws { ... try addProvider(Argon2Provider.Provider.self) } }
- Update the
droplet.json
file in the Config folder to useargon2
as the hash implementation:{ ... "hash": "argon2" }
- (Optional) Customize Argon2 with the
argon2.json
file.
Customization
You can create a new configuration file called argon2.json
in the Config folder to override the parameters of the Argon2 function.
See the following table for possible options and their default values:
Key | Type | Default value | Explanation |
---|---|---|---|
variant |
string | "i" | The Argon2 algorithm has three variants with different performance characteristics: d , i and id . See here for more details. Setting an invalid name will throw an error on boot. |
timeCost |
number | 3 | The number of iterations |
memoryCost |
number | 12 | Memory usage of the function as 2^N KiB |
parallelism |
number | 1 | Number of threads used for parallelism |
saltLength |
number | 32 | Length of the random salt in bytes |