Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions services/api/.env
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ ADMIN_PASSWORD=development.now
# JWT Secret to sign and encrypt tokens
JWT_SECRET=m6bv7!m|E:7:*X3Mx7I)2+Y>B70+&K

# bcrypt cost factor for password hashes
BCRYPT_SALT_PASSES=12

# App details for emails
APP_NAME=Bedrock
APP_URL=http://localhost:2200
Expand Down
5 changes: 4 additions & 1 deletion services/api/src/utils/auth/password.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
import bcrypt from 'bcryptjs';
import config from '@bedrockio/config';

import { clearAuthenticators, addAuthenticator, assertAuthenticator } from './authenticators.js';

// 5 minutes
const MFA_THRESHOLD = 5 * 60 * 1000;

const BCRYPT_SALT_PASSES = config.get('BCRYPT_SALT_PASSES', 'number');

async function verifyPassword(user, password) {
const authenticator = assertAuthenticator(user, 'password');

Expand Down Expand Up @@ -34,7 +37,7 @@ function verifyRecentPassword(user) {
}

async function setPassword(user, password) {
const salt = await bcrypt.genSalt(12);
const salt = await bcrypt.genSalt(BCRYPT_SALT_PASSES);
const hash = await bcrypt.hash(password, salt);

clearAuthenticators(user, 'password');
Expand Down
3 changes: 3 additions & 0 deletions services/api/vitest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ import { defineConfig } from 'vitest/config';

process.env.ENV_NAME = 'test';
process.env.LOG_LEVEL ||= 'warn';
// Hashing at the production cost of 12 takes ~200ms per password, which dominates
// the auth tests. 4 is the minimum bcrypt accepts.
process.env.BCRYPT_SALT_PASSES ||= '4';

export default defineConfig({
test: {
Expand Down
Loading