Browse Source

* HTTPServer.cpp : true random password

pull/588/head
hagen 8 years ago
parent
commit
97da8e2f2e
  1. 8
      HTTPServer.cpp

8
HTTPServer.cpp

@ -782,12 +782,14 @@ namespace http {
std::string pass; i2p::config::GetOption("http.pass", pass); std::string pass; i2p::config::GetOption("http.pass", pass);
/* generate pass if needed */ /* generate pass if needed */
if (needAuth && pass == "") { if (needAuth && pass == "") {
uint8_t random[16];
char alnum[] = "0123456789" char alnum[] = "0123456789"
"ABCDEFGHIJKLMNOPQRSTUVWXYZ" "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
"abcdefghijklmnopqrstuvwxyz"; "abcdefghijklmnopqrstuvwxyz";
pass.resize(16); pass.resize(sizeof(random));
for (size_t i = 0; i < pass.size(); i++) { RAND_bytes(random, sizeof(random));
pass[i] = alnum[rand() % (sizeof(alnum) - 1)]; for (size_t i = 0; i < sizeof(random); i++) {
pass[i] = alnum[random[i] % (sizeof(alnum) - 1)];
} }
i2p::config::SetOption("http.pass", pass); i2p::config::SetOption("http.pass", pass);
LogPrint(eLogInfo, "HTTPServer: password set to ", pass); LogPrint(eLogInfo, "HTTPServer: password set to ", pass);

Loading…
Cancel
Save