Browse Source

move prompt_password from wallet.py to main script

283
ThomasV 12 years ago
parent
commit
d92f1991a9
  1. 21
      electrum
  2. 2
      lib/__init__.py
  3. 19
      lib/wallet.py
  4. 6
      upgrade.py

21
electrum

@ -36,9 +36,9 @@ except ImportError:
sys.exit("Error: AES does not seem to be installed. Try 'sudo pip install slowaes'") sys.exit("Error: AES does not seem to be installed. Try 'sudo pip install slowaes'")
try: try:
from lib import Wallet, WalletSynchronizer, format_satoshis, mnemonic, prompt_password, SimpleConfig, pick_random_server from lib import Wallet, WalletSynchronizer, format_satoshis, mnemonic, SimpleConfig, pick_random_server
except ImportError: except ImportError:
from electrum import Wallet, WalletSynchronizer, format_satoshis, mnemonic, prompt_password, SimpleConfig, pick_random_server from electrum import Wallet, WalletSynchronizer, format_satoshis, mnemonic, SimpleConfig, pick_random_server
from decimal import Decimal from decimal import Decimal
@ -107,6 +107,23 @@ offline_commands = [ 'password', 'mktx',
protected_commands = ['payto', 'password', 'mktx', 'seed', 'import','signmessage' ] protected_commands = ['payto', 'password', 'mktx', 'seed', 'import','signmessage' ]
# get password routine
def prompt_password(prompt, confirm=True):
import getpass
if sys.stdin.isatty():
password = getpass.getpass(prompt)
if password and confirm:
password2 = getpass.getpass("Confirm: ")
if password != password2:
sys.exit("Error: Passwords do not match.")
else:
password = raw_input(prompt)
if not password:
password = None
return password
if __name__ == '__main__': if __name__ == '__main__':
usage = "usage: %prog [options] command\nCommands: "+ (', '.join(known_commands)) usage = "usage: %prog [options] command\nCommands: "+ (', '.join(known_commands))

2
lib/__init__.py

@ -1,3 +1,3 @@
from wallet import Wallet, format_satoshis, prompt_password from wallet import Wallet, format_satoshis
from interface import WalletSynchronizer, Interface, pick_random_server from interface import WalletSynchronizer, Interface, pick_random_server
from simple_config import SimpleConfig from simple_config import SimpleConfig

19
lib/wallet.py

@ -26,7 +26,6 @@ import operator
import ast import ast
import threading import threading
import random import random
import getpass
import aes import aes
import ecdsa import ecdsa
@ -158,24 +157,6 @@ def ASecretToSecret(key):
########### end pywallet functions ####################### ########### end pywallet functions #######################
# get password routine
def prompt_password(prompt, confirm=True):
if sys.stdin.isatty():
password = getpass.getpass(prompt)
if password and confirm:
password2 = getpass.getpass("Confirm: ")
if password != password2:
sys.exit("Error: Passwords do not match.")
else:
password = raw_input(prompt)
if not password:
password = None
return password
# URL decode # URL decode
_ud = re.compile('%([0-9a-hA-H]{2})', re.MULTILINE) _ud = re.compile('%([0-9a-hA-H]{2})', re.MULTILINE)

6
upgrade.py

@ -1,11 +1,9 @@
import electrum, base64, ast, sys, os import electrum, base64, ast, sys, os, getpass
from version import SEED_VERSION from version import SEED_VERSION
try: try:
from lib import prompt_password
from lib.util import print_error from lib.util import print_error
except ImportError: except ImportError:
from electrum import prompt_password
from electrum.util import print_error from electrum.util import print_error
if __name__ == "__main__": if __name__ == "__main__":
@ -55,7 +53,7 @@ if __name__ == "__main__":
DecodeAES = lambda secret, e: AES.new(secret).decrypt(base64.b64decode(e)).rstrip(PADDING) DecodeAES = lambda secret, e: AES.new(secret).decrypt(base64.b64decode(e)).rstrip(PADDING)
print "Please enter your password" print "Please enter your password"
password = prompt_password("Password:") password = getpass.getpass("Password:")
secret = electrum.Hash(password) secret = electrum.Hash(password)
try: try:
seed = DecodeAES( secret, wallet.seed ) seed = DecodeAES( secret, wallet.seed )

Loading…
Cancel
Save