hash method

Result<String> hash(
  1. String password
)
override

Hashes a password using bcrypt with auto-generated salt. Returns Result<String> with hash or error. Note: The same password will produce different hashes each time due to unique salts.

Implementation

Result<String> hash(String password) {
  if (password.isEmpty) {
    return Result.error('[InvalidArgument] Password is empty');
  }
  try {
    final salt = BCrypt.gensalt();
    final hash = BCrypt.hashpw(password, salt);
    return Result.value(hash);
  } catch (e) {
    return Result.error('[Internal] Hashing failed: $e');
  }
}