Programming Tutorial: How to change the password of bot accounts in bulk

You are a big splinterland bot camp, you want to change your password in bulk, and here is the solution.....

We need to prepare a few things:

DependencyVersionSource
python3.xhttps://www.python.org/downloads/
Beem0.24.26(or latest)https://pypi.org/project/beem/

My Code:


import time
import requests
from binascii import hexlify
from beemgraphenebase.ecdsasig import sign_message
from beemgraphenebase.account import PasswordKey
from beem import Hive



import secrets
from beemgraphenebase.account import PasswordKey, BrainKey



def compute_sig(string_to_sign: str, priv_key: str):
    bytestring_signature = sign_message(string_to_sign, priv_key)
    sig = hexlify(bytestring_signature).decode("ascii")
    return sig


def login(private_key: str, username: str):
    login_endpoint = "https://api2.splinterlands.com/players/login"
    ts = int(time.time() * 1000)
    sig = compute_sig(username + str(ts), private_key)
    login_endpoint += "?name=" + username + "&ts=" + str(ts) + "&sig=" + sig
    return requests.get(login_endpoint)


file1 = open('ChangePass_input.txt', 'r')
Lines = file1.readlines()
t=0
for line in Lines:
       t=t+1
total = t

file_object = open('ChangePass_output.txt', 'a')
i=0
for line in Lines:
    i=i+1
    new_account_name = line.split(':')[0].strip()
    wif = line.split(':')[1].strip()
    master_key = secrets.token_urlsafe(32)

    #owner key
    wif = line.split(':')[1].strip()

    hive = Hive(keys=[wif])

    #creator = hive.wallet.getAccountFromPrivateKey(wif)

    active_key = PasswordKey(new_account_name, master_key, role="active", prefix="STM")
    owner_key = PasswordKey(new_account_name, master_key, role="owner", prefix="STM")
    posting_key = PasswordKey(new_account_name, master_key, role="posting", prefix="STM")
    memo_key = PasswordKey(new_account_name, master_key, role="memo", prefix="STM")

    active_privkey = str(active_key.get_private_key()).strip()
    posting_privkey = str(posting_key.get_private_key()).strip()
    owner_privkey = str(owner_key.get_private_key()).strip()
    memo_privkey = str(memo_key.get_private_key()).strip()

    print(new_account_name)
    print("master key")
    print(master_key)
    print("Owner Private Key")
    print(owner_privkey)
    print("Active Private Key")
    print(active_privkey)
    print("Posting Private Key")
    print(posting_privkey)
    print("Memo Private Key")
    print(memo_privkey)
    #print(len(memo_privkey))

    print(hive.update_account(account=new_account_name,password=master_key))
    time.sleep(2)
    checkname =hive.wallet.getAccountFromPrivateKey(owner_privkey)
    Result = checkname + ":"+ new_account_name.strip() +":" + master_key.strip()+ ":" + owner_privkey + ":" +active_privkey +":" + posting_privkey +"\n"
    file_object.write(Result)
    
    print(Result)
    print("Done || ",i,"/",total,checkname, "||", new_account_name)

Demo Video:

Small tool mistakenly shared to everyone. Guided by a friend

H2
H3
H4
3 columns
2 columns
1 column
Join the conversation now
Logo
Center