external ldap: ensure dashboard login does totp check
This commit is contained in:
11
src/users.js
11
src/users.js
@@ -360,11 +360,8 @@ async function verify(userId, password, identifier, options) {
|
||||
return user;
|
||||
}
|
||||
|
||||
const skipTotpCheck = !!options.skipTotpCheck;
|
||||
const totpToken = options.totpToken || null;
|
||||
|
||||
if (user.source === 'ldap') {
|
||||
await externalLdap.verifyPassword(user.username, password, totpToken);
|
||||
await externalLdap.verifyPassword(user.username, password, options);
|
||||
} else {
|
||||
const saltBinary = Buffer.from(user.salt, 'hex');
|
||||
const [error, derivedKey] = await safe(pbkdf2Async(password, saltBinary, CRYPTO_ITERATIONS, CRYPTO_KEY_LENGTH, CRYPTO_DIGEST));
|
||||
@@ -373,9 +370,9 @@ async function verify(userId, password, identifier, options) {
|
||||
const derivedKeyHex = Buffer.from(derivedKey, 'binary').toString('hex');
|
||||
if (derivedKeyHex !== user.password) throw new BoxError(BoxError.INVALID_CREDENTIALS, 'Username and password does not match');
|
||||
|
||||
if (!skipTotpCheck && user.twoFactorAuthenticationEnabled) {
|
||||
if (!totpToken) throw new BoxError(BoxError.INVALID_CREDENTIALS, 'A totpToken must be provided');
|
||||
const verified = speakeasy.totp.verify({ secret: user.twoFactorAuthenticationSecret, encoding: 'base32', token: totpToken, window: 2 });
|
||||
if (!options.skipTotpCheck && user.twoFactorAuthenticationEnabled) {
|
||||
if (!options.totpToken) throw new BoxError(BoxError.INVALID_CREDENTIALS, 'A totpToken must be provided');
|
||||
const verified = speakeasy.totp.verify({ secret: user.twoFactorAuthenticationSecret, encoding: 'base32', token: options.totpToken, window: 2 });
|
||||
if (!verified) throw new BoxError(BoxError.INVALID_CREDENTIALS, 'Invalid totpToken');
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user