I had the same problem. I had created a wallet using geth
and somehow I wrote down the wrong password. I used the simple python
code below to solve the issue. I know it's not pretty, but I just needed a quick solution to my problem. Someone else might pick this up and make a proper tool, or perhaps I get around to it one day as a good python
learning experience. I tested some 100k password and I was able to recover using this code. It follows a similar format as pyethrecover
(the presale tool) and uses pyethereum
to decode the keystore file.
You need to download/install the pyethereum
library: https://github.com/ethereum/pyethereum
See documentation there for requirements and how to.
From pyethereum
we need keys.py
which has the function decode_keystore_json
from keys import decode_keystore_json #keys.py from pyethereum, we only want the decode_keystore_json function
import json
import itertools
import sys
f = open('wallet.json') # the json account file from keystore, here renamed
jsondata=json.load(f)
Run the following if you have a text file with the different passwords you want to try written down, one on each line:
# Reading possible passwords from a text file
with open('listofpasswords.txt') as fpw: # a text file with possible passwords on each line
lines = fpw.read().splitlines()
n_pws = len(lines)
print 'Number of passwords to test: %d' % (n_pws,)
i=1
for l in lines:
try:
decode_keystore_json(jsondata,l)
print '\n*** found password in text file:'
print l
break
except:
sys.stdout.write("\r#%d %s" % (i,l)) #prints simple progress with # in list that is tested and the pw string
sys.stdout.flush()
i+=1
Or this code if you want to construct passwords from possible combinations (see pyethrecover example 2):
# Constructing passwords from possible combinations (see doc of pyethrecover)
grammar=[
('correct',),
('horse','donkey'),
('staple','STAPLE'),
('','battery')
]
pwds=[]
def generate_all(el, tr): #taken from pyethrecover
if el:
for j in xrange(len(el[0])):
for w in generate_all(el[1:], tr + el[0][j]):
yield w
else:
yield tr
pwds = itertools.chain(pwds, generate_all(grammar,''))
pwds_l = list(pwds)
n_pws = len(pwds_l)
print 'Number of passwords to test: %d' % (n_pws,)
i=1
for l in pwds_l:
try:
decode_keystore_json(jsondata,l)
print '\n*** found password in grammar list:'
print l
break
except:
sys.stdout.write("\r#%d %s" % (i,l)) #prints simple progress with # in list that is tested and the pw string
sys.stdout.flush()
i+=1
Good luck!