]> vaikene.ee Git - evaf/blobdiff - src/apps/PswGen/CLI/cli.cpp
Fixed setting the password length argument that was not possible to change once store...
[evaf] / src / apps / PswGen / CLI / cli.cpp
index fbc8450ebe37f2ec2ddba2170994a536587df353..1b59e8b25ba2189523053fe9c4d9b559639cb4bb 100644 (file)
@@ -159,7 +159,7 @@ void Module::generatePassword()
 {
     QString masterPassword;
     QString appName;
-    int passwordLength = DefaultPasswordLength;
+    int passwordLength = 0;
 
     // Process command-line arguments
     QStringList args = QCoreApplication::arguments();
@@ -199,10 +199,14 @@ void Module::generatePassword()
     QExplicitlySharedDataPointer<PswGen::Storage::Data> data;
     if (mStorage) {
         data = mStorage->query(appName);
-        if (data)
+        if (data && passwordLength == 0)
             passwordLength = data->length();
     }
 
+    // If the length argument is still not initialized, use the default length value
+    if (!passwordLength)
+        passwordLength = DefaultPasswordLength;
+
     // Generate password
     QString password = mGenerator->generatePassword(appName, masterPassword, passwordLength);
     cout << "Generated password : " << password << endl;
@@ -211,6 +215,8 @@ void Module::generatePassword()
     if (mStorage) {
         if (!data)
             data = new Storage::Data(appName, passwordLength);
+        else
+            data->setLength(passwordLength);
         mStorage->save(appName, data);
     }
 }