From 20e9a6027b85c947e59722a061de1479bc2d7953 Mon Sep 17 00:00:00 2001
From: Enar Vaikene <enar.vaikene@logica.com>
Date: Mon, 4 Jun 2012 10:07:47 +0300
Subject: [PATCH] Implemented the ALPHANUMERIC flag for password generation.
 Makes sure that all the characters in the generated password are
 alpha-numeric only.

---
 src/apps/PswGen/Generator/module.cpp | 18 ++++++++++++++----
 src/apps/PswGen/Generator/version.h  |  6 +++---
 2 files changed, 17 insertions(+), 7 deletions(-)

diff --git a/src/apps/PswGen/Generator/module.cpp b/src/apps/PswGen/Generator/module.cpp
index e19933b..9e24e56 100644
--- a/src/apps/PswGen/Generator/module.cpp
+++ b/src/apps/PswGen/Generator/module.cpp
@@ -3,7 +3,7 @@
  * @brief Implementation of the iGenerator interface
  * @author Enar Vaikene
  *
- * Copyright (c) 2011 Enar Vaikene
+ * Copyright (c) 2011-2012 Enar Vaikene
  *
  * This file is part of the eVaf C++ cross-platform application development framework.
  *
@@ -94,7 +94,17 @@ QString GeneratorImpl::generatePassword(QString const & name, QString const & ma
     hash.addData(inputString);
     QByteArray result = hash.result().toBase64();
     if (length > 0)
-        return result.left(length);
-    else
-        return result;
+        result.resize(length);
+
+    if (flags & uint(ALPHANUMERIC)) {
+        // Convert all characters to alpha-numeric
+        for (int i = 0; i < result.size(); ++i) {
+            unsigned char c = result.at(i);
+            while (isalnum(c) == 0)
+                c++;
+            result[i] = c;
+        }
+    }
+
+    return result;
 }
diff --git a/src/apps/PswGen/Generator/version.h b/src/apps/PswGen/Generator/version.h
index b118cdc..c2e78d0 100644
--- a/src/apps/PswGen/Generator/version.h
+++ b/src/apps/PswGen/Generator/version.h
@@ -3,7 +3,7 @@
  * @brief Version information for eVaf modules
  * @author Enar Vaikene
  *
- * Copyright (c) 2011 Enar Vaikene
+ * Copyright (c) 2011-2012 Enar Vaikene
  *
  * This file is part of the eVaf C++ cross-platform application development framework.
  *
@@ -25,12 +25,12 @@
 /**
  * Module/library version number in the form major,minor,release,build
  */
-#define VER_FILE_VERSION                0,1,1,1
+#define VER_FILE_VERSION                0,1,2,2
 
 /**
  * Module/library version number in the string format (shall end with \0)
  */
-#define VER_FILE_VERSION_STR            "0.1.1.1\0"
+#define VER_FILE_VERSION_STR            "0.1.2.2\0"
 
 /**
  * Module/library name (shall end with \0)
-- 
2.49.0