Chromium Code Reviews| Index: remoting/host/host_secret.cc |
| diff --git a/remoting/host/host_secret.cc b/remoting/host/host_secret.cc |
| index 1ed86224e0ad0297214394b46f3ae57125d6d116..b7b9368b2c9508487dbe4c1d05723939556c6c82 100644 |
| --- a/remoting/host/host_secret.cc |
| +++ b/remoting/host/host_secret.cc |
| @@ -4,6 +4,8 @@ |
| #include "remoting/host/host_secret.h" |
| +#include <iomanip> |
| +#include <sstream> |
| #include <vector> |
| #include "base/logging.h" |
| @@ -17,7 +19,8 @@ namespace { |
| // 5 digits means 100K possible host secrets with uniform distribution, which |
| // should be enough for short-term passwords, given that we rate-limit guesses |
| // in the cloud and expire access codes after a small number of attempts. |
| -const int kMaxHostSecret = 100000; |
| +const int kHostSecretLength = 5; |
| +const int kMaxHostSecret = 100000; // Must be equal 10^kHostSecretLength. |
|
Wez
2011/11/30 00:34:26
Can this be 10^kHostSecretLength, or will that end
Sergey Ulanov
2011/11/30 01:12:26
Done.
|
| // Generates cryptographically strong random number in the range [0, max). |
| int CryptoRandomInt(int max) { |
| @@ -29,7 +32,10 @@ int CryptoRandomInt(int max) { |
| } // namespace |
| std::string GenerateSupportHostSecret() { |
| - return base::IntToString(CryptoRandomInt(kMaxHostSecret)); |
| + std::stringstream out; |
| + out << std::setfill('0') << std::setw(kHostSecretLength) |
| + << CryptoRandomInt(kMaxHostSecret); |
| + return out.str(); |
|
Wez
2011/11/30 00:34:26
Ick. Beginning to think the byte-by-byte version
Sergey Ulanov
2011/11/30 01:12:26
Yes. Some other code in chromium uses the same app
|
| } |
| } // namespace remoting |