aboutsummaryrefslogtreecommitdiffstats
path: root/src/core/function/PassphraseGenerator.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/core/function/PassphraseGenerator.cpp')
-rw-r--r--src/core/function/PassphraseGenerator.cpp22
1 files changed, 22 insertions, 0 deletions
diff --git a/src/core/function/PassphraseGenerator.cpp b/src/core/function/PassphraseGenerator.cpp
index 84ca8e8c..261f1606 100644
--- a/src/core/function/PassphraseGenerator.cpp
+++ b/src/core/function/PassphraseGenerator.cpp
@@ -27,3 +27,25 @@
*/
#include "PassphraseGenerator.h"
+
+#include <boost/format.hpp>
+
+namespace GpgFrontend {
+
+std::string PassphraseGenerator::Generate(int len) {
+ std::uniform_int_distribution<int> dist(999, 99999);
+
+ auto file_string = boost::format("KeyPackage_%1%") % dist(mt_);
+ 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;
+}
+} // namespace GpgFrontend \ No newline at end of file