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.
9 from random
import SystemRandom
14 sys
.stderr
.write('Please include username as an argument.\n')
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')
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
)