Use the variable name _ for unused return values
[bitcoinplatinum.git] / share / rpcuser / rpcuser.py
blob63c69e308af24404eb6ba96e458747a87535c09f
1 #!/usr/bin/env python2
2 # Copyright (c) 2015-2016 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.
6 import hashlib
7 import sys
8 import os
9 from random import SystemRandom
10 import base64
11 import hmac
13 if len(sys.argv) < 2:
14 sys.stderr.write('Please include username as an argument.\n')
15 sys.exit(0)
17 username = sys.argv[1]
19 #This uses os.urandom() underneath
20 cryptogen = SystemRandom()
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])
27 #Create 32 byte b64 password
28 password = base64.urlsafe_b64encode(os.urandom(32))
30 digestmod = hashlib.sha256
32 if sys.version_info.major >= 3:
33 password = password.decode('utf-8')
34 digestmod = 'SHA256'
36 m = hmac.new(bytearray(salt, 'utf-8'), bytearray(password, 'utf-8'), digestmod)
37 result = m.hexdigest()
39 print("String to be appended to bitcoin.conf:")
40 print("rpcauth="+username+":"+salt+"$"+result)
41 print("Your password:\n"+password)