From 1e932e72edcd9379f4c9ef3704c43e06ad012222 Mon Sep 17 00:00:00 2001 From: Raymond Feng Date: Wed, 3 Dec 2014 09:03:36 -0800 Subject: [PATCH] Allow native bcrypt for performance See https://github.com/strongloop/loopback/issues/892 --- common/models/user.js | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/common/models/user.js b/common/models/user.js index 019894c5..563d0363 100644 --- a/common/models/user.js +++ b/common/models/user.js @@ -6,7 +6,16 @@ var loopback = require('../../lib/loopback'); var path = require('path'); var SALT_WORK_FACTOR = 10; var crypto = require('crypto'); -var bcrypt = require('bcryptjs'); + +var bcrypt; +try { + // Try the native module first + bcrypt = require('bcrypt'); +} catch (err) { + // Fall back to pure JS impl + bcrypt = require('bcryptjs'); +} + var DEFAULT_TTL = 1209600; // 2 weeks in seconds var DEFAULT_RESET_PW_TTL = 15 * 60; // 15 mins in seconds var DEFAULT_MAX_TTL = 31556926; // 1 year in seconds