MMoSP003C- steem-python 定制修改密码的工具

in #esteemlast year (edited)

MMoSP003C- steem-python 定制修改密码的工具

一般我们从官网 steemit.com 注册账号,相对比较安全.

密码丢失后(被盗后),可以找 steemit.com 帮助恢复.

当然,能被恢复,就意味着被其他人更改.但steem机制时,如果上一次密码不能提供,则无法恢复.

因此,不管我们的账号是从哪儿获得,连续改两次密码,并保留两次更改的密码,则只能有自己能够恢复密码了,其他人就不能恢复密码.

我们一般登陆 steemit.com,在官方在线钱包中 修改密码,但就比较麻烦,不如直接命令行用工具改.

这里就示范一个修改密码的工具(MMoSP003_customize_a_tools_for_change_keys.py):

#!/usr/bin/env python
# -*- coding: UTF-8 -*-

# 修改 steem 帐号密码
# python MMoSP003_customize_a_tools_for_change_keys acc wif
# acc:steem账户名
# wif:steem账户名旧的 owner private key

import sys
import json
import steem
import steembase
from steem.steemd import Steemd
from steem.instance import set_shared_steemd_instance
from steembase.account import PasswordKey, BrainKey
from steembase import operations

# 必须参数
try:
    acc = sys.argv[1]
    wif = sys.argv[2]
except Exception as e:
    sys.exit()
print('acc:', acc)
print('wif:', wif)

steemd_api_nodes = [
    'https://anyx.io',
    'https://api.steemit.com'
]
stm = Steemd(nodes=steemd_api_nodes)
set_shared_steemd_instance(stm)

# 生成一套新密码
bk = BrainKey()
brainkey = bk.get_brainkey()
print('brain key:', str(brainkey))
prikey = str(bk.get_private())
print('private key:', str(prikey))
pubkey = format(bk.get_public(), "STM")
print('public key:', str(pubkey))

# 获取整套密钥
posting_key = PasswordKey(acc, pubkey, role="posting")
active_key = PasswordKey(acc, pubkey, role="active")
memo_key = PasswordKey(acc, pubkey, role="memo")
owner_key = PasswordKey(acc, pubkey, role="owner")
# 提取整套密钥中的私钥
active_privkey = active_key.get_private_key()
posting_privkey = posting_key.get_private_key()
owner_privkey = owner_key.get_private_key()
memo_privkey = memo_key.get_private_key()
print('posting_privkey:', str(posting_privkey))
print('active_privkey:', str(active_privkey))
print('owner_privkey:', str(owner_privkey))
print('memo_privkey:', str(memo_privkey))
# 提取整套密钥中的公钥
# active_pubkey = active_key.get_public_key()
# owner_pubkey = owner_key.get_public_key()
# posting_pubkey = posting_key.get_public_key()
memo_pubkey = memo_key.get_public_key()
print('memo_pubkey:', str(memo_pubkey))

try:
    old_owner_key = str(PasswordKey(acc, wif, "owner").get_private_key())

    client = steem.Steem(nodes=steemd_api_nodes, keys=[old_owner_key])
    #client = steem.Steem(nodes=['https://testnet.steem.vc'], keys=[wif])

    new_pubkey = {}
    for role in ["owner", "active", "posting", "memo"]:
        private_key = PasswordKey(
            acc, pubkey, role).get_private_key()
        new_pubkey[role] = str(private_key.pubkey)

    new_data = {
        "account": acc,
        "json_metadata": {},
        "owner": {
            "key_auths": [
                [new_pubkey["owner"], 1]
            ],
            "account_auths": [],
            "weight_threshold": 1
        },
        "active": {
            "key_auths": [
                [new_pubkey["active"], 1]
            ],
            "account_auths": [],
            "weight_threshold": 1
        },
        "posting": {
            "key_auths": [
                [new_pubkey["posting"], 1]
            ],
            "account_auths": [],
            "weight_threshold": 1
        },
        "memo_key": new_pubkey["memo"]
    }
    print("New data:", new_data)

    op = operations.AccountUpdate(**new_data)
    result = client.commit.finalizeOp(op, acc, "owner")
    print("Result:", result)
except Exception as err:
    print(acc, " err:", err)

执行程序:python MMoSP003_customize_a_tools_for_change_keys dappcoder ownerkey
执行结果,和预期一致:
屏幕快照 2020-02-17 上午2.58.34.png

English list:

#esteem #hive-139531 #steemdevs #community #programming
MMoSP000E-< make money on steem-python > Preface
MMoSP001E- install steem python with anaconda
MMoSP002E - use steem-python make a robot that can automatically say hello to contents under the tag

中文列表

#cn #hive-180932 #chinese #hive-143316
MMoSP000C-《steem-python赚钱实战教程》序言
MMoSP001C- Anaconda 安装 steem-python 开发环境
MMoSP002C- steem-python 开发一个会自动问某个标签下内容的机器人

Sort:  

Congratulations @dappcoder! You have completed the following achievement on the Steem blockchain and have been rewarded with new badge(s) :

You distributed more than 800 upvotes. Your next target is to reach 900 upvotes.

You can view your badges on your Steem Board and compare to others on the Steem Ranking
If you no longer want to receive notifications, reply to this comment with the word STOP

To support your work, I also upvoted your post!

Do not miss the last post from @steemitboard:

Valentine's day challenge - Give a badge to your beloved!
Vote for @Steemitboard as a witness to get one more award and increased upvotes!

Coin Marketplace

STEEM 0.50
TRX 0.07
JST 0.057
BTC 40609.83
ETH 2809.00
USDT 1.00
SBD 7.02