@@ -2368,18 +2368,25 @@ void ThreadRPCServer2(void* parg)
2368
2368
printf (" ThreadRPCServer started\n " );
2369
2369
2370
2370
strRPCUserColonPass = mapArgs[" -rpcuser" ] + " :" + mapArgs[" -rpcpassword" ];
2371
- if (strRPCUserColonPass == " : " )
2371
+ if (mapArgs[ " -rpcpassword " ] == " " )
2372
2372
{
2373
+ unsigned char rand_pwd[32 ];
2374
+ RAND_bytes (rand_pwd, 32 );
2373
2375
string strWhatAmI = " To use bitcoind" ;
2374
2376
if (mapArgs.count (" -server" ))
2375
2377
strWhatAmI = strprintf (_ (" To use the %s option" ), " \" -server\" " );
2376
2378
else if (mapArgs.count (" -daemon" ))
2377
2379
strWhatAmI = strprintf (_ (" To use the %s option" ), " \" -daemon\" " );
2378
2380
PrintConsole (
2379
- _ (" Error: %s, you must set rpcpassword=<password>\n in the configuration file: %s\n "
2381
+ _ (" Error: %s, you must set a rpcpassword in the configuration file:\n %s\n "
2382
+ " It is recommended you use the following random password:\n "
2383
+ " rpcuser=bitcoinrpc\n "
2384
+ " rpcpassword=%s\n "
2385
+ " (you do not need to remember this password)\n "
2380
2386
" If the file does not exist, create it with owner-readable-only file permissions.\n " ),
2381
2387
strWhatAmI.c_str (),
2382
- GetConfigFile ().c_str ());
2388
+ GetConfigFile ().c_str (),
2389
+ EncodeBase58 (&rand_pwd[0 ],&rand_pwd[0 ]+32 ).c_str ());
2383
2390
#ifndef QT_GUI
2384
2391
CreateThread (Shutdown, NULL );
2385
2392
#endif
@@ -2468,12 +2475,14 @@ void ThreadRPCServer2(void* parg)
2468
2475
}
2469
2476
if (!HTTPAuthorized (mapHeaders))
2470
2477
{
2471
- // Deter brute-forcing short passwords
2472
- if (mapArgs[" -rpcpassword" ].size () < 15 )
2473
- Sleep (50 );
2478
+ printf (" ThreadRPCServer incorrect password attempt from %s\n " ,peer.address ().to_string ().c_str ());
2479
+ /* Deter brute-forcing short passwords.
2480
+ If this results in a DOS the user really
2481
+ shouldn't have their RPC port exposed.*/
2482
+ if (mapArgs[" -rpcpassword" ].size () < 20 )
2483
+ Sleep (250 );
2474
2484
2475
2485
stream << HTTPReply (401 , " " ) << std::flush;
2476
- printf (" ThreadRPCServer incorrect password attempt\n " );
2477
2486
continue ;
2478
2487
}
2479
2488
0 commit comments