rpcauth: Support storing credentials in a file

To be used with -rpcauthfile
This commit is contained in:
João Barbosa 2020-11-16 23:59:24 +00:00 committed by Luke Dashjr
parent 98965fdadc
commit 6d69a2974b

View File

@ -24,6 +24,7 @@ def main():
parser = ArgumentParser(description='Create login credentials for a JSON-RPC user') parser = ArgumentParser(description='Create login credentials for a JSON-RPC user')
parser.add_argument('username', help='the username for authentication') parser.add_argument('username', help='the username for authentication')
parser.add_argument('password', help='leave empty to generate a random password or specify "-" to prompt for password', nargs='?') parser.add_argument('password', help='leave empty to generate a random password or specify "-" to prompt for password', nargs='?')
parser.add_argument('--output', dest='output', help='file to store credentials, to be used with -rpcauthfile')
args = parser.parse_args() args = parser.parse_args()
if not args.password: if not args.password:
@ -35,9 +36,14 @@ def main():
salt = generate_salt(16) salt = generate_salt(16)
password_hmac = password_to_hmac(salt, args.password) password_hmac = password_to_hmac(salt, args.password)
print('String to be appended to bitcoin.conf:') if args.output:
print(f'rpcauth={args.username}:{salt}${password_hmac}') file = open(args.output, "x")
print(f'Your password:\n{args.password}') file.write(f'{args.username}:{salt}${password_hmac}')
print(f'Your password:\n{args.password}')
else:
print('String to be appended to bitcoin.conf:')
print(f'rpcauth={args.username}:{salt}${password_hmac}')
print(f'Your password:\n{args.password}')
if __name__ == '__main__': if __name__ == '__main__':
main() main()