Dash Core  0.12.2.1
P2P Digital Currency
rpcuser.py
Go to the documentation of this file.
1 #!/usr/bin/env python2
2 # Copyright (c) 2015 The Bitcoin Core developers
3 # Distributed under the MIT software license, see the accompanying
4 # file COPYING or http://www.opensource.org/licenses/mit-license.php.
5 
6 import hashlib
7 import sys
8 import os
9 from random import SystemRandom
10 import base64
11 import hmac
12 
13 if len(sys.argv) < 2:
14  sys.stderr.write('Please include username as an argument.\n')
15  sys.exit(0)
16 
17 username = sys.argv[1]
18 
19 #This uses os.urandom() underneath
20 cryptogen = SystemRandom()
21 
22 #Create 16 byte hex salt
23 salt_sequence = [cryptogen.randrange(256) for i in range(16)]
24 hexseq = list(map(hex, salt_sequence))
25 salt = "".join([x[2:] for x in hexseq])
26 
27 #Create 32 byte b64 password
28 password = base64.urlsafe_b64encode(os.urandom(32))
29 
30 digestmod = hashlib.sha256
31 
32 if sys.version_info.major >= 3:
33  password = password.decode('utf-8')
34  digestmod = 'SHA256'
35 
36 m = hmac.new(bytearray(salt, 'utf-8'), bytearray(password, 'utf-8'), digestmod)
37 result = m.hexdigest()
38 
39 print("String to be appended to bitcoin.conf:")
40 print("rpcauth="+username+":"+salt+"$"+result)
41 print("Your password:\n"+password)