~sircmpwn/pass-rotate

ref: 837d726c037a6d52bd5cbf159a75386a39e4dea0 pass-rotate/passrotate/providers/facebook.py -rw-r--r-- 1.7 KiB
837d726cDrew DeVault Merge pull request #29 from gabm/AddPassName 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
from passrotate.provider import Provider, ProviderOption, register_provider
from passrotate.forms import get_form
import requests

class Facebook(Provider):
    """
    [facebook.com]
    username=Your Facebook username
    """
    name = "Facebook"
    domains = [
        "facebook.com",
    ]
    options = {
        "username": ProviderOption(str, "Your Facebook username")
    }

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

    def prepare(self, old_password):
        self._session = requests.Session()

        ###authenticate
        r = self._session.get("https://m.facebook.com/login.php")
        form = get_form(r.text, id="login_form")
        form.update({
            "email": self.username,
            "pass": old_password
            })
        r = self._session.post("https://m.facebook.com/login.php", data=form)

        ###check for authentication failure
        if "The email address that you've entered doesn't match any account" in r.text:
            raise Exception("Facebook doesn't recognise this email")
        if "The password you entered is incorrect" in r.text:
            raise Exception("Incorrect password")

        ###load form
        r = self._session.get("https://m.facebook.com/settings/security/password/")
        self._form = get_form(r.text, method="post")

    def execute(self, old_password, new_password):
        self._form.update({
            "password_old" : old_password,
            "password_new" : new_password,
            "password_confirm" : new_password
            })
        r = self._session.post("https://m.facebook.com/password/change/", data=self._form)

register_provider(Facebook)