I'm creating an authentication system using python and web3.py.
I'm trying to authenticate a user using

from web3.auto import w3

msg = 'sdb41554xcb4xc548cxd84dxcb'
message = encode_defunct(text=msg)
signed_message = w3.eth.account.sign_message(message, private_key=private_key)
x = w3.eth.account.recover_message(message, signature=signed_message.signature)

if x.lower() == addr.lower():
     return 'AUTHENTICATED'

where addr is the account address of the user store in DB.

For this, the user has to provide his private_key every time. But what I want is that the user only provides the passphrase(which was earlier used while creating the account). His public_key is already stored in Database with his profile.

My question is:

Is there any way that whenever the user provides his passphrase and public_key(coming from DB), private_key is automatically retrieved and thus can be used to sign the message? Any library or something present for the same?

I don't want the user to remember his private_key for the whole time.(While passphrase can be remembered)

Other way: I can import the account in Metamask and whenever he logs in, Metamask prompts open to sign the message. But this will make Metamask compulsory for the users which I don't want.

  • web3py.readthedocs.io/en/stable/… may be you should use smth like this – Igor Sobolev Sep 16 '19 at 9:30
  • Where is the private key? Stored at the server or at the user? – Ismael Sep 16 '19 at 16:33
  • @Ismael stored with the user only – Prachi Sharma Sep 17 '19 at 7:57
  • @IgorSobolev sendTransaction() requires transaction id, and to get transaction id, the user has to perform some transactions which indirectly requires private key. – Prachi Sharma Sep 17 '19 at 7:59
  • Why do you have problems retrieving the private key if the client has a single one? Unless you have a centralized service to manage keys the easiest way is to use a mnemonic and let each user store them, but then you have to sign everything at client side. – Ismael Sep 17 '19 at 17:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.