BcryptContext constructor
BcryptContext({
- required int cost,
- List<
int> ? salt, - BcryptVersion version = BcryptVersion.$2b,
Creates an BcryptContext instance from encoded string.
Parameters:
version: The BcryptVersion to use. DefaultBcryptVersion.$2b.salt: An uniquely and randomly generated string.cost: Number of rounds in terms of power of 2. 0 <cost< 31.
Implementation
factory BcryptContext({
required int cost,
List<int>? salt,
BcryptVersion version = BcryptVersion.$2b,
}) {
// validate parameters
if (cost < 0) {
throw ArgumentError('The cost must be at least 0');
}
if (cost > 31) {
throw ArgumentError('The cost must be at most 31');
}
salt ??= randomBytes(16);
if (salt.length != 16) {
throw ArgumentError('The salt must be exactly 16-bytes');
}
return BcryptContext._(
cost: cost,
version: version,
salt: salt is Uint8List ? salt : Uint8List.fromList(salt),
);
}