|
|
@@ -30,6 +30,8 @@ const BCRYPT_ROUNDS =
|
|
|
Settings != null ? Settings.security : undefined,
|
|
|
x => x.bcryptRounds
|
|
|
) || 12
|
|
|
+const BCRYPT_MINOR_VERSION =
|
|
|
+ (Settings != null ? Settings.security.bcryptMinorVersion : undefined) || 'a'
|
|
|
|
|
|
const _checkWriteResult = function(result, callback) {
|
|
|
// for MongoDB
|
|
|
@@ -211,40 +213,46 @@ module.exports = AuthenticationManager = {
|
|
|
}
|
|
|
},
|
|
|
|
|
|
+ hashPassword(password, callback) {
|
|
|
+ return bcrypt.genSalt(BCRYPT_ROUNDS, BCRYPT_MINOR_VERSION, function(
|
|
|
+ error,
|
|
|
+ salt
|
|
|
+ ) {
|
|
|
+ if (error != null) {
|
|
|
+ return callback(error)
|
|
|
+ }
|
|
|
+ return bcrypt.hash(password, salt, callback)
|
|
|
+ })
|
|
|
+ },
|
|
|
+
|
|
|
setUserPasswordInV2(user_id, password, callback) {
|
|
|
const validation = this.validatePassword(password)
|
|
|
if (validation != null) {
|
|
|
return callback(validation.message)
|
|
|
}
|
|
|
- const minorVersion = 'a'
|
|
|
- return bcrypt.genSalt(BCRYPT_ROUNDS, minorVersion, function(error, salt) {
|
|
|
+ return this.hashPassword(password, function(error, hash) {
|
|
|
if (error != null) {
|
|
|
return callback(error)
|
|
|
}
|
|
|
- return bcrypt.hash(password, salt, function(error, hash) {
|
|
|
- if (error != null) {
|
|
|
- return callback(error)
|
|
|
- }
|
|
|
- return db.users.update(
|
|
|
- {
|
|
|
- _id: ObjectId(user_id.toString())
|
|
|
- },
|
|
|
- {
|
|
|
- $set: {
|
|
|
- hashedPassword: hash
|
|
|
- },
|
|
|
- $unset: {
|
|
|
- password: true
|
|
|
- }
|
|
|
+ return db.users.update(
|
|
|
+ {
|
|
|
+ _id: ObjectId(user_id.toString())
|
|
|
+ },
|
|
|
+ {
|
|
|
+ $set: {
|
|
|
+ hashedPassword: hash
|
|
|
},
|
|
|
- function(updateError, result) {
|
|
|
- if (updateError != null) {
|
|
|
- return callback(updateError)
|
|
|
- }
|
|
|
- return _checkWriteResult(result, callback)
|
|
|
+ $unset: {
|
|
|
+ password: true
|
|
|
}
|
|
|
- )
|
|
|
- })
|
|
|
+ },
|
|
|
+ function(updateError, result) {
|
|
|
+ if (updateError != null) {
|
|
|
+ return callback(updateError)
|
|
|
+ }
|
|
|
+ return _checkWriteResult(result, callback)
|
|
|
+ }
|
|
|
+ )
|
|
|
})
|
|
|
},
|
|
|
|