学习笔记,改密码

in STEEM CN/中文5 months ago (edited)

改密码这操作不怎么常用,一直都是在https://steemitwallet.com改密码,从没研究过自己写代码要怎么改密码。

因为怕各种服务挂了,希望绝境下自己也能改,所以今天研究了一下,不算复杂,其实就是从一个密码生成各种KEY,然后广播一个Account_update的事情。

代码如下:

from beem.steem import Steem
from beembase import operations
from beem.transactionbuilder import TransactionBuilder
from beem.account import Account
from beemgraphenebase.account import PasswordKey

nodes = 'https://cn.steems.top'  # 节点

player = "ety003"#用户名
old_password="P5ao368xxxxxxxxx"#老主密码

password="P5M8Txxxxxxxxxxxxxxx"#要改的密码




#从新密码生成KEY
owner_key = PasswordKey(player, password, role="owner")
posting_key = PasswordKey(player, password, role="posting")
active_key = PasswordKey(player, password, role="active")
memo_key = PasswordKey(player, password, role="memo")

#新密码
owner_key2=owner_key.get_private()
posting_key2 = posting_key.get_private()
active_key2 = active_key.get_private()
memo_key2 = memo_key.get_private()
print("新密码")
print("主密码:",password)
print("owner_key:",owner_key2)
print("posting_key:",posting_key2)
print("active_key:",active_key2)
print("memo_key:",memo_key2)

owner_key=owner_key.get_public()
posting_key = posting_key.get_public()
active_key = active_key.get_public()
memo_key = memo_key.get_public()




key = PasswordKey(player, old_password, role="owner")# owner key
key=key.get_private()
key=str(key)


s = Steem(keys=[key], node=nodes)
account = Account(player, steem_instance=s)



who_owner = {'weight_threshold': 1, 'account_auths': [], 'key_auths': [[str(owner_key), 1]]}
who_active = {'weight_threshold': 1, 'account_auths': [], 'key_auths': [[str(active_key), 1]]}
who_posting = {'weight_threshold': 1, 'account_auths': [], 'key_auths': [[str(posting_key), 1]]}



op = operations.Account_update(
    **{
        "account": account["name"],
        "json_metadata": account["json_metadata"],
        "owner": who_owner,
        "active":who_active,
        "posting":who_posting,
        "memo_key": str(memo_key)
    })

tx = TransactionBuilder(steem_instance=s)

tx.appendOps(op)
# 把签名添加并签名
tx.appendSigner(player, "owner")
#tx.appendSigner(player2, "owner")
tx.sign()

# 广播
tx.broadcast()
print("密码修改完成")

完美,以后可以不用跑https://steemitwallet.com改密码了。

准备把改密码操作加到steems.top里面去。

Sort:  

给鱼哥拍手👏

Coin Marketplace

STEEM 0.16
TRX 0.03
JST 0.026
BTC 13122.47
ETH 414.09
USDT 1.00
SBD 1.00