hash static method

String hash(
  1. String password, {
  2. int cost = defaultCost,
})
override

Hash a password using bcrypt

password - The plain text password to hash cost - The cost factor (default: 10). Higher = more secure but slower. Recommended range: 10-12 for production

Returns a bcrypt hash string that includes the salt and cost factor

Implementation

static String hash(String password, {int cost = defaultCost}) {
  if (password.isEmpty) {
    throw ArgumentError('Password cannot be empty');
  }

  if (cost < 4 || cost > 31) {
    throw ArgumentError('Cost must be between 4 and 31');
  }

  return BCrypt.hashpw(password, BCrypt.gensalt(logRounds: cost));
}