sqliteAuthenticationHandler.js 1023 B

12345678910111213141516171819202122232425
  1. import { TotpChecker } from "./totpChecker.js";
  2. export class SqliteAuthenticationHandler {
  3. passwordEncoder;
  4. getAccountInformation;
  5. constructor(getAccountInformationFunction, passwordEncoder) {
  6. this.passwordEncoder = passwordEncoder;
  7. this.getAccountInformation = getAccountInformationFunction;
  8. }
  9. async needTotp(username, _password) {
  10. const accountInformation = await this.getAccountInformation(username);
  11. if (!accountInformation)
  12. return null;
  13. return !!accountInformation.totpSecret;
  14. }
  15. async tryLogin(username, password, totp) {
  16. const accountInformation = await this.getAccountInformation(username);
  17. if (!accountInformation)
  18. return null;
  19. password = this.passwordEncoder(password);
  20. if (accountInformation.passwordEncoded !== password)
  21. return false;
  22. return TotpChecker.ValidateTotp(accountInformation.totpSecret, totp);
  23. }
  24. }
  25. //# sourceMappingURL=sqliteAuthenticationHandler.js.map