2024-02-27 14:52:55 +01:00
|
|
|
from pyotp import TOTP
|
|
|
|
|
2024-02-27 11:26:55 +01:00
|
|
|
from modules.Tools.logger import debug, warning
|
|
|
|
|
|
|
|
|
|
|
|
class UserCredentials:
|
|
|
|
def __init__(self):
|
|
|
|
self.data = {}
|
|
|
|
self.current = 0
|
|
|
|
self.total = 0
|
|
|
|
|
|
|
|
def add(self, username: str, password: str, tfa: str = None):
|
2024-02-28 14:44:01 +01:00
|
|
|
debug(
|
|
|
|
f"adding account with data : Username: {username}, Password: {password}, 2FA: {'None' if tfa == '' else tfa}")
|
2024-02-27 11:26:55 +01:00
|
|
|
self.data[self.total] = {
|
|
|
|
"username": username,
|
|
|
|
"password": password,
|
|
|
|
"2fa": None if tfa == '' else tfa
|
|
|
|
}
|
|
|
|
self.total += 1
|
|
|
|
|
|
|
|
def tfa_enable(self):
|
|
|
|
return self.data[self.current]["2fa"] is not None
|
|
|
|
|
|
|
|
def get_mail(self):
|
|
|
|
return self.data[self.current]["username"]
|
|
|
|
|
|
|
|
def get_password(self):
|
|
|
|
return self.data[self.current]["password"]
|
|
|
|
|
|
|
|
def get_tfa(self):
|
|
|
|
if not self.tfa_enable():
|
2024-04-10 12:14:41 +02:00
|
|
|
warning("Warning: TFA is not enabled. Can't get a TFA code.")
|
|
|
|
return None
|
2024-03-01 17:29:15 +01:00
|
|
|
return TOTP(self.data[self.current]["2fa"])
|
2024-02-27 11:26:55 +01:00
|
|
|
|
|
|
|
def next_account(self):
|
|
|
|
self.current += 1
|
2024-02-28 14:44:01 +01:00
|
|
|
if self.is_valid():
|
|
|
|
debug(f"New credentials: {self.data[self.current]}")
|
|
|
|
else:
|
|
|
|
debug("No new credentials.")
|
2024-02-27 11:26:55 +01:00
|
|
|
|
|
|
|
def is_valid(self):
|
2024-04-10 10:29:53 +02:00
|
|
|
return (self.current < self.total
|
|
|
|
and self.get_mail() != "" and self.get_mail is not None)
|