|
|
@@ -9,7 +9,6 @@
|
|
|
/*
|
|
|
* decaffeinate suggestions:
|
|
|
* DS102: Remove unnecessary code created because of implicit returns
|
|
|
- * DS103: Rewrite code to no longer use __guard__
|
|
|
* DS202: Simplify dynamic range loops
|
|
|
* DS207: Consider shorter variations of null checks
|
|
|
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
|
|
|
@@ -25,13 +24,8 @@ const Errors = require('../Errors/Errors')
|
|
|
const UserGetter = require('../User/UserGetter')
|
|
|
const V1Handler = require('../V1/V1Handler')
|
|
|
|
|
|
-const BCRYPT_ROUNDS =
|
|
|
- __guard__(
|
|
|
- Settings != null ? Settings.security : undefined,
|
|
|
- x => x.bcryptRounds
|
|
|
- ) || 12
|
|
|
-const BCRYPT_MINOR_VERSION =
|
|
|
- (Settings != null ? Settings.security.bcryptMinorVersion : undefined) || 'a'
|
|
|
+const BCRYPT_ROUNDS = Settings.security.bcryptRounds || 12
|
|
|
+const BCRYPT_MINOR_VERSION = Settings.security.bcryptMinorVersion || 'a'
|
|
|
|
|
|
const _checkWriteResult = function(result, callback) {
|
|
|
// for MongoDB
|
|
|
@@ -107,24 +101,17 @@ module.exports = AuthenticationManager = {
|
|
|
return { message: 'password not set' }
|
|
|
}
|
|
|
|
|
|
- const allowAnyChars =
|
|
|
- (Settings.passwordStrengthOptions != null
|
|
|
- ? Settings.passwordStrengthOptions.allowAnyChars
|
|
|
- : undefined) === true
|
|
|
- const min =
|
|
|
- __guard__(
|
|
|
- Settings.passwordStrengthOptions != null
|
|
|
- ? Settings.passwordStrengthOptions.length
|
|
|
- : undefined,
|
|
|
- x1 => x1.min
|
|
|
- ) || 6
|
|
|
- let max =
|
|
|
- __guard__(
|
|
|
- Settings.passwordStrengthOptions != null
|
|
|
- ? Settings.passwordStrengthOptions.length
|
|
|
- : undefined,
|
|
|
- x2 => x2.max
|
|
|
- ) || 72
|
|
|
+ let allowAnyChars, min, max
|
|
|
+ if (Settings.passwordStrengthOptions) {
|
|
|
+ allowAnyChars = Settings.passwordStrengthOptions.allowAnyChars === true
|
|
|
+ if (Settings.passwordStrengthOptions.length) {
|
|
|
+ min = Settings.passwordStrengthOptions.length.min
|
|
|
+ max = Settings.passwordStrengthOptions.length.max
|
|
|
+ }
|
|
|
+ }
|
|
|
+ allowAnyChars = !!allowAnyChars
|
|
|
+ min = min || 6
|
|
|
+ max = max || 72
|
|
|
|
|
|
// we don't support passwords > 72 characters in length, because bcrypt truncates them
|
|
|
if (max > 72) {
|
|
|
@@ -196,12 +183,7 @@ module.exports = AuthenticationManager = {
|
|
|
if (callback == null) {
|
|
|
callback = function(error) {}
|
|
|
}
|
|
|
- if (
|
|
|
- __guard__(
|
|
|
- Settings != null ? Settings.security : undefined,
|
|
|
- x1 => x1.disableBcryptRoundsUpgrades
|
|
|
- )
|
|
|
- ) {
|
|
|
+ if (Settings.security.disableBcryptRoundsUpgrades) {
|
|
|
return callback()
|
|
|
}
|
|
|
// check current number of rounds and rehash if necessary
|
|
|
@@ -274,34 +256,20 @@ module.exports = AuthenticationManager = {
|
|
|
},
|
|
|
|
|
|
_passwordCharactersAreValid(password) {
|
|
|
- const digits =
|
|
|
- __guard__(
|
|
|
- Settings.passwordStrengthOptions != null
|
|
|
- ? Settings.passwordStrengthOptions.chars
|
|
|
- : undefined,
|
|
|
- x1 => x1.digits
|
|
|
- ) || '1234567890'
|
|
|
- const letters =
|
|
|
- __guard__(
|
|
|
- Settings.passwordStrengthOptions != null
|
|
|
- ? Settings.passwordStrengthOptions.chars
|
|
|
- : undefined,
|
|
|
- x2 => x2.letters
|
|
|
- ) || 'abcdefghijklmnopqrstuvwxyz'
|
|
|
- const letters_up =
|
|
|
- __guard__(
|
|
|
- Settings.passwordStrengthOptions != null
|
|
|
- ? Settings.passwordStrengthOptions.chars
|
|
|
- : undefined,
|
|
|
- x3 => x3.letters_up
|
|
|
- ) || 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
|
|
|
- const symbols =
|
|
|
- __guard__(
|
|
|
- Settings.passwordStrengthOptions != null
|
|
|
- ? Settings.passwordStrengthOptions.chars
|
|
|
- : undefined,
|
|
|
- x4 => x4.symbols
|
|
|
- ) || '@#$%^&*()-_=+[]{};:<>/?!£€.,'
|
|
|
+ let digits, letters, letters_up, symbols
|
|
|
+ if (
|
|
|
+ Settings.passwordStrengthOptions &&
|
|
|
+ Settings.passwordStrengthOptions.chars
|
|
|
+ ) {
|
|
|
+ digits = Settings.passwordStrengthOptions.chars.digits
|
|
|
+ letters = Settings.passwordStrengthOptions.chars.letters
|
|
|
+ letters_up = Settings.passwordStrengthOptions.chars.letters_up
|
|
|
+ symbols = Settings.passwordStrengthOptions.chars.symbols
|
|
|
+ }
|
|
|
+ digits = digits || '1234567890'
|
|
|
+ letters = letters || 'abcdefghijklmnopqrstuvwxyz'
|
|
|
+ letters_up = letters_up || 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
|
|
|
+ symbols = symbols || '@#$%^&*()-_=+[]{};:<>/?!£€.,'
|
|
|
|
|
|
for (
|
|
|
let charIndex = 0, end = password.length - 1, asc = end >= 0;
|
|
|
@@ -320,9 +288,3 @@ module.exports = AuthenticationManager = {
|
|
|
return true
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
-function __guard__(value, transform) {
|
|
|
- return typeof value !== 'undefined' && value !== null
|
|
|
- ? transform(value)
|
|
|
- : undefined
|
|
|
-}
|