-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathcrypt.py
executable file
·66 lines (52 loc) · 1.9 KB
/
crypt.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#!/usr/bin/env python
from hashlib import sha512
from passlib import hash
from ciphvar import *
import ConfigParser
import logging
import getpass
import sqlite3
import Cryptsy
import random
db = 'cobot.db'
Config = ConfigParser.ConfigParser()
Config.read('./crypt.conf')
cryptsyPub = Config.get('Api-Key', 'pub')
cryptsyKey = Config.get('Api-Key', 'key').decode('string_escape') # decode() is necesary to strip
# extra escape chars
# Setup Debug messages
logging.basicConfig(format='%(levelname)s:%(message)s', level=logging.DEBUG)
def getCreds(dbname, uname):
conn = sqlite3.connect(dbname)
cont = conn.cursor()
cont.execute('SELECT hash FROM users WHERE user=?', uname)
hashSplice = cont.fetchone()[0]
return (hashSplice.split('$')[2], hashSplice.split('$')[3])
conn.close()
def logIn():
hashsalt, hashdb = getCreds(db, ('geod',))
pw = getpass.getpass('Password: ')
hashCheck = hash.sha512_crypt.encrypt(pw, salt=hashsalt, rounds=5000).split('$')[3]
retries = 3
for retry in range(0,retries):
if hashCheck == hashdb:
global cryptsyKey
cryptsyKey = decrypt(cryptsyKey, pw)
logging.debug('Decrypted Key: %s' % cryptsyKey)
pw = (len(pw) + random.randint(1, 32))*'x'
logging.debug('Password x\'ed: %s' % pw)
del pw
return True
else:
print 'Incorrect Password, Try Again.'
pw = getpass.getpass('Password: ')
pw = (len(pw) + random.randint(1, 32))*'x'
logging.debug('Password x\'ed: %s' % pw)
del pw
return False
if logIn():
marketd = Cryptsy.Cryptsy(cryptsyPub, cryptsyKey)
datum = marketd.getMarkets()
print datum
for x in datum['return']:
print "%s Vol: %s" %(x['primary_currency_code'], x['current_volume'])