-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.py
86 lines (79 loc) · 3.95 KB
/
main.py
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
print('Auther')
import argparse
import asyncio
import json
import os
import time
import urllib.request
from datetime import datetime, timezone
import aiohttp
import requests
from colorama import Fore, Style, init
#from msauth import login
name = input("Email: ")
passw = input('Password: ')
def inp(text):
print(f"{Fore.YELLOW}{text}", end="")
ret = input("")
return ret
async def get_mojang_token(email: name, password: passw):
# Login code is partially from mcsniperpy thx!
questions = []
async with aiohttp.ClientSession() as session:
authenticate_json = {"username": email, "password": password}
headers = {"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:83.0) Gecko/20100101 Firefox/83.0",
"Content-Type": "application/json"}
async with session.post("https://authserver.mojang.com/authenticate", json=authenticate_json,
headers=headers) as r:
# print(r.status)
if r.status == 200:
resp_json = await r.json()
# print(resp_json)
auth = {"Authorization": "Bearer: " + resp_json["accessToken"]}
access_token = resp_json["accessToken"]
# print(f"{Fore.LIGHTGREEN_EX}Auth: {auth}\n\nAccess Token: {access_token}")
else:
print(f"{Fore.LIGHTRED_EX}INVALID CREDENTIALS{Fore.RESET}")
async with session.get("https://api.mojang.com/user/security/challenges", headers=auth) as r:
answers = []
if r.status < 300:
resp_json = await r.json()
if resp_json == []:
async with session.get("https://api.minecraftservices.com/minecraft/profile/namechange",
headers={"Authorization": "Bearer " + access_token}) as nameChangeResponse:
ncjson = await nameChangeResponse.json()
print(ncjson)
try:
if ncjson["nameChangeAllowed"] is False:
print(
"Your Account is not"
" eligible for a name change!"
)
exit()
else:
print(f"{Fore.LIGHTGREEN_EX}Logged into your account successfully!{Fore.RESET}")
print("Your bearer token is: " + access_token)
except Exception:
print("logged in correctly")
print("Your bearer token is: " + access_token)
else:
try:
for x in range(3):
ans = inp({resp_json[x]["question"]["question"]})
answers.append({"id": resp_json[x]["answer"]["id"], "answer": ans})
except IndexError:
print(f"{Fore.LIGHTRED_EX}Please provide answers to the security questions{Fore.RESET}")
return
async with session.post("https://api.mojang.com/user/security/location", json=answers,
headers=auth) as r:
try:
if r.status < 300:
print(f"{Fore.LIGHTGREEN_EX}Logged in{Fore.RESET}")
print("Your bearer token is: " + access_token)
except RuntimeError:
print("")
if r.status > 300:
print(
f"{Fore.LIGHTRED_EX}Security Questions answers were incorrect, restart the program!{Fore.RESET}")
asyncio.run(get_mojang_token(name, passw))
os.system('python utils/check.py')