class UnsetPasswordValidator(wx.PyValidator): def __init__(self, parent): wx.PyValidator.__init__(self) self.parent = parent self.frame = self.parent.GetTopLevelParent() self.keychain = MyKeyChain() self.type = self.getType() self.Bind(wx.EVT_TEXT, self.OnText) def camelize(self, type): return str(type[0].lower() + type[1:]) def getType(self): if self.parent.type[:3] == "set": return self.camelize(self.parent.type[3:]) else: return self.camelize(self.parent.type[5:]) def OnText(self, event=None): old = self.parent.FindWindowByName("oldPassword") if self.keychain.isKey(self.type) == True: if self.keychain.comparePassword(self.type, old.GetValue()) == True: self.parent.FindWindowByName("goButton").Enable() return True self.parent.FindWindowByName("goButton").Disable() return False def Clone(self): return UnsetPasswordValidator(self.parent) def Validate(self, event=None): return True def TransferToWindow(self): textCtrl = self.GetWindow() if self.keychain.isKey(self.type) == False: self.parent.FindWindowByName("oldPasswordLabel").Disable() self.parent.FindWindowByName("oldPassword").Disable() def TransferFromWindow(self): if self.OnText() == True: if self.keychain.isKey(self.type) == True: self.keychain.removePassword(self.type) return True
class UnsetPasswordValidator(wx.PyValidator): def __init__(self, parent): wx.PyValidator.__init__(self) self.parent = parent self.frame = self.parent.GetTopLevelParent() self.keychain = MyKeyChain() self.type = self.getType() self.Bind(wx.EVT_TEXT, self.OnText) def camelize(self, type): return str(type[0].lower() + type[1:]) def getType(self): if self.parent.type[:3] == "set": return self.camelize(self.parent.type[3:]) else: return self.camelize(self.parent.type[5:]) def OnText(self, event=None): old = self.parent.FindWindowByName("oldPassword") if self.keychain.isKey(self.type) == True: if self.keychain.comparePassword(self.type, old.GetValue()) == True: self.parent.FindWindowByName("goButton").Enable() return True self.parent.FindWindowByName("goButton").Disable() return False def Clone(self): return UnsetPasswordValidator(self.parent) def Validate(self, event=None): return True def TransferToWindow(self): textCtrl = self.GetWindow() if self.keychain.isKey(self.type) == False: self.parent.FindWindowByName("oldPasswordLabel").Disable() self.parent.FindWindowByName("oldPassword").Disable() def TransferFromWindow(self): if self.OnText() == True: if self.keychain.isKey(self.type) == True: self.keychain.removePassword(self.type) return True
class WelcomeValidator(wx.PyValidator): """Validates all widgets of class TemplateDesignerWelcome The validator checks, of password is required and calls class TemplateDesignerFrame if all checks run successfully """ def __init__(self, parent): wx.PyValidator.__init__(self) self.parent = parent self.frame = self.parent.GetTopLevelParent() self.keychain = MyKeyChain() self.Bind(wx.EVT_RADIOBUTTON, self.OnRadio) self.Bind(wx.EVT_BUTTON, self.OnButton) self.Bind(wx.EVT_TEXT, self.OnText) def OnText(self, event=None): """Checks if entered password is correct If password is correct, ok button becomes enabled """ textCtrl = self.GetWindow() for selection in ["fullAccess", "restrictedAccess", "viewAccess"]: radio = self.parent.FindWindowByName(selection) compare = self.keychain.comparePassword(selection, textCtrl.GetValue()) if radio.GetValue() == True and compare == True: self.parent.goButton.Enable() return True self.parent.goButton.Disable() def OnButton(self, event=None): """Calls the class TemplateDesignerFrame if user input is valid if user input is valid, returns True, else returns False """ textCtrl = self.GetWindow() if textCtrl.GetName() == "goButton": for selection in ["fullAccess", "restrictedAccess", "viewAccess"]: radio = self.parent.FindWindowByName(selection) pw = self.parent.FindWindowByName("password") if pw.IsEnabled() == True and radio.GetValue() == True: compare = self.keychain.comparePassword( selection, pw.GetValue()) if compare == True: self.parent.OnExitWindow() frame = TemplateDesignerFrame(None, selection) frame.Show(True) elif pw.IsEnabled() == False and radio.GetValue() == True: self.parent.OnExitWindow() frame = TemplateDesignerFrame(None, selection) frame.Show(True) return False def OnRadio(self, event=None): """Enables and Disables the password text control dependend on the system settings returns True """ textCtrl = self.GetWindow() for selection in ["fullAccess", "restrictedAccess", "viewAccess"]: check = self.keychain.isKey(selection) if textCtrl.GetName() == selection and check == True: self.parent.FindWindowByName("passwordLabel").Enable() self.parent.FindWindowByName("password").Enable() self.parent.FindWindowByName("password").SetValue("") self.parent.goButton.Disable() return True elif textCtrl.GetName() == selection and check == False: self.parent.FindWindowByName("passwordLabel").Disable() self.parent.FindWindowByName("password").Disable() self.parent.goButton.Enable() return True def Clone(self): return WelcomeValidator(self.parent) def Validate(self): return True def TransferToWindow(self): return True def TransferFromWindow(self): return True
class WelcomeValidator(wx.PyValidator): """Validates all widgets of class TemplateDesignerWelcome The validator checks, of password is required and calls class TemplateDesignerFrame if all checks run successfully """ def __init__(self, parent): wx.PyValidator.__init__(self) self.parent = parent self.frame = self.parent.GetTopLevelParent() self.keychain = MyKeyChain() self.Bind(wx.EVT_RADIOBUTTON, self.OnRadio) self.Bind(wx.EVT_BUTTON, self.OnButton) self.Bind(wx.EVT_TEXT, self.OnText) def OnText(self, event=None): """Checks if entered password is correct If password is correct, ok button becomes enabled """ textCtrl = self.GetWindow() for selection in ["fullAccess", "restrictedAccess", "viewAccess"]: radio = self.parent.FindWindowByName(selection) compare = self.keychain.comparePassword(selection, textCtrl.GetValue()) if radio.GetValue() == True and compare == True: self.parent.goButton.Enable() return True self.parent.goButton.Disable() def OnButton(self, event=None): """Calls the class TemplateDesignerFrame if user input is valid if user input is valid, returns True, else returns False """ textCtrl = self.GetWindow() if textCtrl.GetName() == "goButton": for selection in ["fullAccess", "restrictedAccess", "viewAccess"]: radio = self.parent.FindWindowByName(selection) pw = self.parent.FindWindowByName("password") if pw.IsEnabled() == True and radio.GetValue() == True: compare = self.keychain.comparePassword(selection, pw.GetValue()) if compare == True: self.parent.OnExitWindow() frame = TemplateDesignerFrame(None, selection) frame.Show(True) elif pw.IsEnabled() == False and radio.GetValue() == True: self.parent.OnExitWindow() frame = TemplateDesignerFrame(None, selection) frame.Show(True) return False def OnRadio(self, event=None): """Enables and Disables the password text control dependend on the system settings returns True """ textCtrl = self.GetWindow() for selection in ["fullAccess", "restrictedAccess", "viewAccess"]: check = self.keychain.isKey(selection) if textCtrl.GetName() == selection and check == True: self.parent.FindWindowByName("passwordLabel").Enable() self.parent.FindWindowByName("password").Enable() self.parent.FindWindowByName("password").SetValue("") self.parent.goButton.Disable() return True elif textCtrl.GetName() == selection and check == False: self.parent.FindWindowByName("passwordLabel").Disable() self.parent.FindWindowByName("password").Disable() self.parent.goButton.Enable() return True def Clone(self): return WelcomeValidator(self.parent) def Validate(self): return True def TransferToWindow(self): return True def TransferFromWindow(self): return True
class SetPasswordValidator(wx.PyValidator): def __init__(self, parent): wx.PyValidator.__init__(self) self.parent = parent self.frame = self.parent.GetTopLevelParent() self.keychain = MyKeyChain() self.type = self.getType() self.Bind(wx.EVT_TEXT, self.OnText) def camelize(self, type): return str(type[0].lower() + type[1:]) def getType(self): if self.parent.type[:3] == "set": return self.camelize(self.parent.type[3:]) else: return self.camelize(self.parent.type[5:]) def checkPasswordQuality(self, password): """checkPasswordQuality returns True if given passwords are at least 5 signs long and include and include alpha and numeric values Else returns False """ if re.match(r"(.*[0-9]+.*[a-zA-Z]+.*)|(.*[a-zA-Z]+.*[0-9]+.*)", password) \ and len(password) > 4: return True return False def OnText(self, event=None): old = self.parent.FindWindowByName("oldPassword") new = self.parent.FindWindowByName("newPassword") repeat = self.parent.FindWindowByName("repeatPassword") if self.keychain.isKey(self.type) == True: if self.keychain.comparePassword(self.type, old.GetValue()) == True: quality = self.checkPasswordQuality(repeat.GetValue()) if new.GetValue() == repeat.GetValue() and quality == True: self.parent.FindWindowByName("goButton").Enable() return True else: quality = self.checkPasswordQuality(repeat.GetValue()) if new.GetValue() == repeat.GetValue() and quality == True: self.parent.FindWindowByName("goButton").Enable() return True self.parent.FindWindowByName("goButton").Disable() return False def Clone(self): return SetPasswordValidator(self.parent) def Validate(self, event=None): return True def TransferToWindow(self): textCtrl = self.GetWindow() if self.keychain.isKey(self.type) == False: self.parent.FindWindowByName("oldPasswordLabel").Disable() self.parent.FindWindowByName("oldPassword").Disable() def TransferFromWindow(self): if self.OnText() == True: password = self.parent.FindWindowByName("repeatPassword").GetValue() if self.keychain.isKey(self.type) == True: self.keychain.changePassword(self.type, password) else: self.keychain.setPassword(self.type, password) return True