[chore] Use same basic code logic in user as in basicAuth

ad316c6d78679f27f362d8664e68d43dca0de836

QuantumEntangledAndy <sheepchaan@gmail.com>

Signed
1 files changed, +9 -6Showing whitespace changes
src/users.js+9 -6
@@ -656,22 +656,25 @@ async function basicUserLogin(request) {
656656 return false;
657657 }
658658
659659 const authHeader = request.get('Authorization')headers.authorization;
660+
660661 if (!authHeader) {
661662 return false;
662663 }
663664
664665 const parts[scheme, credentials] = authHeader.split(' ');
665- if (!parts || parts.length < 2 || parts[0].toLowerCase() !== 'basic') {
666+
667+ if (scheme !== 'Basic' || !credentials) {
666668 return false;
667669 }
668670
669- const b64auth = parts[1];
671+ const [username, password] = Buffer.from(credentials, 'base64')
670- const [login, password] = Buffer.from(b64auth, 'base64').toString().split(':');
672+ .toString('utf8')
673+ .split(':');
671674
672675 const userHandles = await getAllUserHandles();
673676 for (const userHandle of userHandles) {
674677 if (loginusername === userHandle) {
675678 const user = await storage.getItem(toKey(userHandle));
676679 // Verify pass again here just to be sure
677680 if (user && user.enabled && user.password && user.password === getPasswordHash(password, user.salt)) {