aboutsummaryrefslogtreecommitdiffstats
path: root/src/core/function/PassphraseGenerator.h
diff options
context:
space:
mode:
authorSaturneric <[email protected]>2022-03-12 07:00:14 +0000
committerSaturneric <[email protected]>2022-03-12 07:00:14 +0000
commitf129055af41c44eed2a6423dfaf52c054458f0b4 (patch)
treed117164d3e9a2af58a60de4c58f225938245bc04 /src/core/function/PassphraseGenerator.h
parentMerge branch 'develop-2.0.5' of git.codesdream.com:GpgFrontend into develop-2... (diff)
downloadGpgFrontend-f129055af41c44eed2a6423dfaf52c054458f0b4.tar.gz
GpgFrontend-f129055af41c44eed2a6423dfaf52c054458f0b4.zip
<fix>(core): Fix the existing problem of the key package
1. Fix the password generation function 2. Add some log output
Diffstat (limited to 'src/core/function/PassphraseGenerator.h')
-rw-r--r--src/core/function/PassphraseGenerator.h14
1 files changed, 12 insertions, 2 deletions
diff --git a/src/core/function/PassphraseGenerator.h b/src/core/function/PassphraseGenerator.h
index 5e55b2dd..d1cc7607 100644
--- a/src/core/function/PassphraseGenerator.h
+++ b/src/core/function/PassphraseGenerator.h
@@ -42,7 +42,6 @@ namespace GpgFrontend {
class PassphraseGenerator
: public SingletonFunctionObject<PassphraseGenerator> {
public:
-
/**
* @brief PassphraseGenerator constructor
*
@@ -60,8 +59,19 @@ class PassphraseGenerator
*/
std::string Generate(int len) {
std::uniform_int_distribution<int> dist(999, 99999);
+
auto file_string = boost::format("KeyPackage_%1%") % dist(mt_);
- return file_string.str();
+ static const char alphanum[] =
+ "0123456789"
+ "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
+ "abcdefghijklmnopqrstuvwxyz";
+ std::string tmp_str;
+ tmp_str.reserve(len);
+
+ for (int i = 0; i < len; ++i) {
+ tmp_str += alphanum[dist(mt_) % (sizeof(alphanum) - 1)];
+ }
+ return tmp_str;
}
std::random_device rd_; ///< Random device