diff --git a/lib/profile-utils.js b/lib/profile-utils.js new file mode 100644 index 00000000..323a43f5 --- /dev/null +++ b/lib/profile-utils.js @@ -0,0 +1,10 @@ +const bcrypt = require('bcryptjs'); +const saltRounds = process.env.NODE_ENV == 'test' ? 5 : 12; + +const encodePassword = async input => { + const salt = await bcrypt.genSalt(saltRounds); + + return await bcrypt.hash(input, salt); +}; + +module.exports = { encodePassword }; diff --git a/package.json b/package.json index ecce56a8..c070098f 100644 --- a/package.json +++ b/package.json @@ -28,6 +28,7 @@ }, "dependencies": { "async": "0.9.0", + "bcryptjs": "2.4.3", "camelcase": "^4.1.0", "cp-i18n-lib": "git+https://github.com/CoderDojo/cp-i18n-lib.git", "cp-logs-lib": "git://github.com/CoderDojo/cp-logs-lib#1.1.0", diff --git a/yarn.lock b/yarn.lock index e8c3d0d2..0a11067b 100644 --- a/yarn.lock +++ b/yarn.lock @@ -479,6 +479,11 @@ bcrypt-pbkdf@^1.0.0: dependencies: tweetnacl "^0.14.3" +bcryptjs@2.4.3: + version "2.4.3" + resolved "https://registry.yarnpkg.com/bcryptjs/-/bcryptjs-2.4.3.tgz#9ab5627b93e60621ff7cdac5da9733027df1d0cb" + integrity sha1-mrVie5PmBiH/fNrF2pczAn3x0Ms= + big-number@0.3.1: version "0.3.1" resolved "https://registry.yarnpkg.com/big-number/-/big-number-0.3.1.tgz#ac73020c0a59bb79eb17c2ce2db77f77d974e013"