WayrApp Backend & Ecosystem Documentation - v1.0.0
    Preparing search index...

    Function hashPassword

    • Hash password using bcrypt with configurable salt rounds

      Securely hashes a plaintext password using the bcrypt algorithm with a configurable number of salt rounds. The salt rounds determine the computational cost of hashing, with higher values providing better security at the cost of performance.

      The function uses the BCRYPT_SALT_ROUNDS environment variable (default 12) to configure the hashing strength. This allows for security tuning based on deployment requirements and hardware capabilities.

      Parameters

      • password: string

        Plaintext password to hash

      Returns Promise<string>

      Promise resolving to bcrypt hash string

      // Hash password during user registration
      const plainPassword = 'userPassword123!';
      const hashedPassword = await hashPassword(plainPassword);
      console.log(hashedPassword); // '$2b$12$...' (bcrypt hash format)

      // Store hashedPassword in database, never store plaintext
      await userRepository.create({
      email: 'user@example.com',
      password: hashedPassword
      });
      // Configure salt rounds via environment variable
      // BCRYPT_SALT_ROUNDS=10 (faster, less secure)
      // BCRYPT_SALT_ROUNDS=14 (slower, more secure)
      // Default: 12 (balanced security/performance)