MCPcopy Create free account
hub / github.com/bitcoin/bitcoin / CheckUserAuthorized

Function CheckUserAuthorized

src/httprpc.cpp:63–82  ·  view source on GitHub ↗

This function checks username and password against -rpcauth entries from config file.

Source from the content-addressed store, hash-verified

61//This function checks username and password against -rpcauth
62//entries from config file.
63static bool CheckUserAuthorized(std::string_view user, std::string_view pass)
64{
65 for (const auto& fields : g_rpcauth) {
66 if (!TimingResistantEqual(std::string_view(fields[0]), user)) {
67 continue;
68 }
69
70 const std::string& salt = fields[1];
71 const std::string& hash = fields[2];
72
73 std::array<unsigned char, CHMAC_SHA256::OUTPUT_SIZE> out;
74 CHMAC_SHA256(UCharCast(salt.data()), salt.size()).Write(UCharCast(pass.data()), pass.size()).Finalize(out.data());
75 std::string hash_from_pass = HexStr(out);
76
77 if (TimingResistantEqual(hash_from_pass, hash)) {
78 return true;
79 }
80 }
81 return false;
82}
83
84static bool RPCAuthorized(const std::string& strAuth, std::string& strAuthUsernameOut)
85{

Callers 1

RPCAuthorizedFunction · 0.85

Calls 8

TimingResistantEqualFunction · 0.85
CHMAC_SHA256Class · 0.85
UCharCastFunction · 0.85
HexStrFunction · 0.50
FinalizeMethod · 0.45
WriteMethod · 0.45
dataMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected