sqliteAuthenticationHandler.js 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
  2. function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
  3. return new (P || (P = Promise))(function (resolve, reject) {
  4. function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
  5. function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
  6. function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
  7. step((generator = generator.apply(thisArg, _arguments || [])).next());
  8. });
  9. };
  10. import { TotpChecker } from "./totpChecker";
  11. export class SqliteAuthenticationHandler {
  12. constructor(getAccountInformationFunction, passwordEncoder) {
  13. this.passwordEncoder = passwordEncoder;
  14. this.getAccountInformation = getAccountInformationFunction;
  15. }
  16. needTotp(username) {
  17. return __awaiter(this, void 0, void 0, function* () {
  18. const accountInformation = yield this.getAccountInformation(username);
  19. if (!accountInformation)
  20. return null;
  21. return !!accountInformation.totpSecret;
  22. });
  23. }
  24. tryLogin(username, password, totp) {
  25. return __awaiter(this, void 0, void 0, function* () {
  26. const accountInformation = yield this.getAccountInformation(username);
  27. if (!accountInformation)
  28. return null;
  29. password = this.passwordEncoder(password);
  30. if (accountInformation.passwordEncoded !== password ||
  31. (accountInformation.totpSecret && !totp) ||
  32. (!accountInformation.totpSecret && totp))
  33. return false;
  34. if (!accountInformation.totpSecret && !totp)
  35. return true;
  36. return TotpChecker.ValidateTotp(accountInformation.totpSecret, totp);
  37. });
  38. }
  39. }
  40. //# sourceMappingURL=sqliteAuthenticationHandler.js.map