~sircmpwn/pass-rotate

ref: 7a0f1572c61de44c5ceed81c5d65c6830bc45865 pass-rotate/passrotate/providers/discord.py -rw-r--r-- 2.1 KiB
7a0f1572 — Matthias Gabriel add option to override the pass name to be used when rotating the password 4 years ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
from passrotate.provider import Provider, ProviderOption, PromptType, register_provider
import requests

class Discord(Provider):
    """
    [discordapp.com]
    email=Your Discord email address
    """
    name = "Discord"
    domains = [
        "discordapp.com"
    ]
    options = {
        "email": ProviderOption(str, "Your Discord email address")
    }

    def __init__(self, options):
        self.email = options["email"]

    def prepare(self, old_password):
        data = {
            "email": self.email,
            "password": old_password
        }

        self._session = requests.Session()
        r = self._session.post("https://discordapp.com/api/v6/auth/login",
                json=data)

        if r.status_code != 200:
            raise Exception("Unable to log into Discord with your current password: {}".format(r.json()))

        json = r.json()
        if json.get("mfa"):
            code = self.prompt("Enter your two factor (TOTP) code", PromptType.totp)
            data = {
                "code": code,
                "ticket": json.get("ticket")
            }
            r = self._session.post("https://discordapp.com/api/v6/auth/mfa/totp",
                    json=data)

            if r.status_code != 200:
                raise Exception("Failed to authenticate with the TOTP token: {}".format(r.json()))

        self._session.headers["authorization"] = r.json().get("token")

    def execute(self, old_password, new_password):
        data = {
            "password": old_password,
            "new_password": new_password
        }

        while True:
            r = self._session.patch("https://discordapp.com/api/v6/users/@me",
                    json=data)

            if r.status_code != 200:
                json = r.json()
                if json.get("code") == 60008:  # Invalid two-factor code
                    code = self.prompt("Enter your two factor (TOTP) code", PromptType.totp)
                    data["code"] = code
                else:
                    raise Exception("Failed to update Discord password: {}".format(json))
            else:
                break

register_provider(Discord)