~sircmpwn/pass-rotate

ref: 7a0f1572c61de44c5ceed81c5d65c6830bc45865 pass-rotate/passrotate/providers/ycombinator.py -rw-r--r-- 1.4 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
from passrotate.provider import Provider, ProviderOption, register_provider
from passrotate.forms import get_form
import requests

class YCombinator(Provider):
    """
    [news.ycombinator.com]
    username=Your Hacker News username
    """
    name = "YCombinator"
    domains = [
        "ycombinator.com",
        "news.ycombinator.com"
    ]
    options = {
        "username": ProviderOption(str, "Your Hacker News username")
    }

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

    def prepare(self, old_password):
        self._session = requests.Session()
        r = self._session.post("https://news.ycombinator.com/login", data={
            "acct": self.username,
            "pw": old_password
        }, allow_redirects=False)
        if "Bad login" in r.text:
            raise Exception("Unable to log into Hacker News with current password")
        r = self._session.get("https://news.ycombinator.com/changepw")
        self._form = get_form(r.text)

    def execute(self, old_password, new_password):
        self._form.update({ "oldpw": old_password, "pw": new_password })
        r = self._session.post("https://news.ycombinator.com/r",
                               data=self._form, allow_redirects=False)
        if r.status_code != 302:
            raise Exception("Failed to update Hacker News password")

register_provider(YCombinator)