Steem Python Check If User Updates Master Password based on Private Posting Key


Given a Steem Account ID and its private key, how do you check if is correct? The user may update owner password which makes private posting key invalid. If you have managed quite a few accounts, certainly it should be checked programmatically.

The Steem Python Wallet class provides a method to retrieve the account ID based on given private posting key:

1
2
3
4
5
6
7
8
9
10
from keys import accounts  # accounts is a dictionary contains ID-key pairs
from steem import Steem
from nodes import steem_nodes
 
steem = Steem(nodes = steem_nodes)
for id in accounts:  
  key = accounts[id]
  acc = steem.wallet.getAccountFromPrivateKey(key)
  if ((acc == None) or (acc != id)):
    print(id + " has changed password.")
from keys import accounts  # accounts is a dictionary contains ID-key pairs
from steem import Steem
from nodes import steem_nodes

steem = Steem(nodes = steem_nodes)
for id in accounts:  
  key = accounts[id]
  acc = steem.wallet.getAccountFromPrivateKey(key)
  if ((acc == None) or (acc != id)):
    print(id + " has changed password.")

The owner key (master password) should be kept safe and not be used if possible. The private key of steemit account can be used to post, claim rewards and upvotes. From the source of the official STEEM-PYTHON library, here is how it is implemented underneath:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
    def getAccountFromPrivateKey(self, wif):
        """ Obtain account name from private key
        """
        pub = format(PrivateKey(wif).pubkey, self.prefix)
        return self.getAccountFromPublicKey(pub)
 
    def getAccountFromPublicKey(self, pub):
        """ Obtain account name from public key
        """
        # FIXME, this only returns the first associated key.
        # If the key is used by multiple accounts, this
        # will surely lead to undesired behavior
        names = self.steemd.call(
            'get_key_references', [pub], api="account_by_key_api")[0]
        if not names:
            return None
        else:
            return names[0]
    def getAccountFromPrivateKey(self, wif):
        """ Obtain account name from private key
        """
        pub = format(PrivateKey(wif).pubkey, self.prefix)
        return self.getAccountFromPublicKey(pub)

    def getAccountFromPublicKey(self, pub):
        """ Obtain account name from public key
        """
        # FIXME, this only returns the first associated key.
        # If the key is used by multiple accounts, this
        # will surely lead to undesired behavior
        names = self.steemd.call(
            'get_key_references', [pub], api="account_by_key_api")[0]
        if not names:
            return None
        else:
            return names[0]

–EOF (The Ultimate Computing & Technology Blog) —

GD Star Rating
loading...
297 words
Last Post: Turtle Programming v0.0.6: Adding Circle, MoveTo, Turn and Screen!
Next Post: The SteemIt Discord Bot Upgrade and API

The Permanent URL is: Steem Python Check If User Updates Master Password based on Private Posting Key

Leave a Reply