dabo Commit
Revision 6801
Date: 2011-08-27 08:05:23 -0700 (Sat, 27 Aug 2011)
Author: Jacekk
Trac: http://trac.dabodev.com/changeset/6801

Changed:
U   trunk/dabo/ui/dDataControlMixinBase.py

Log:
Added the PersistSecretData property that overrides IsSecret property allowing 
to store sensitive data in encrypted form.

Diff:
Modified: trunk/dabo/ui/dDataControlMixinBase.py
===================================================================
--- trunk/dabo/ui/dDataControlMixinBase.py      2011-08-22 16:32:02 UTC (rev 
6800)
+++ trunk/dabo/ui/dDataControlMixinBase.py      2011-08-27 15:05:23 UTC (rev 
6801)
@@ -305,31 +305,39 @@
 
        def saveValue(self):
                """Save control's value to dApp's user settings table."""
-               if self.IsSecret:
-                       # Don't store sensitive info
-                       return
                if self._DesignerMode:
                        # Don't bother in design mode.
                        return
-               value = self._value  ## on Win, the C++ object is already gone
-               if self.Application:
+               app = self.Application
+               if app:
+                       if self.IsSecret:
+                               # Don't store sensitive info until...
+                               if self.PersistSecretData:
+                                       value = app.encrypt(self._value)
+                               else:
+                                       return
+                       else:
+                               value = self._value  ## on Win, the C++ object 
is already gone
                        if self.RegID:
                                name = "%s.%s" % (self.Form.Name, self.RegID)
                        else:
                                name = self.getAbsoluteName()
-                       self.Application.setUserSetting("%s.Value" % name, 
value)
+                       app.setUserSetting("%s.Value" % name, value)
 
 
        def restoreValue(self):
                """Set the control's value to the value in dApp's user settings 
table."""
-               if self.Application:
+               app = self.Application
+               if app:
                        if self.RegID:
                                name = "%s.%s" % (self.Form.Name, self.RegID)
                        else:
                                name = self.getAbsoluteName()
-                       value = self.Application.getUserSetting("%s.Value" % 
name)
+                       value = app.getUserSetting("%s.Value" % name)
 
                        if value is not None:
+                               if self.IsSecret and self.PersistSecretData:
+                                       value = app.decrypt(value)
                                try:
                                        self.Value = value
                                except (ValueError, TypeError):
@@ -431,6 +439,13 @@
                self._disableOnEmptyDataSource = val
 
 
+       def _getPersistSecretData(self):
+               return getattr(self, "_persistSecretData", False)
+
+       def _setPersistSecretData(self, val):
+               self._persistSecretData = bool(val)
+
+
        def _getSecret(self):
                try:
                        return self._isSecret
@@ -538,6 +553,11 @@
                        _("""Flag for indicating sensitive data, such as 
Password field, that is not
                        to be persisted. Default=False.  (bool)"""))
 
+       PersistSecretData = property(_getPersistSecretData, 
_setPersistSecretData, None,
+                       _("""If True, allow persisting the secret data in 
encrypted form.
+                       Warning! Security of your data strongly depends on used 
encryption algorithms!
+                       Default=False.  (bool)"""))
+
        SaveRestoreValue = property(_getSaveRestoreValue, _setSaveRestoreValue, 
None,
                        _("""Specifies whether the Value of the control gets 
saved when
                        destroyed and restored when created. Use when the 
control isn't



_______________________________________________
Post Messages to: [email protected]
Subscription Maintenance: http://leafe.com/mailman/listinfo/dabo-dev
Searchable Archives: http://leafe.com/archives/search/dabo-dev
This message: 
http://leafe.com/archives/byMID/[email protected]

Reply via email to