Esempio n. 1
0
 def showHidePwd(self):
     if self.checkBox.isChecked(): # show
         self.password.setStyleSheet('')
         self.secret.setStyleSheet('')
         self.password.setText(util.decrypt(config.getMasterPwd(), self.accountObj.pwd))
         self.secret.setPlainText(util.decrypt(config.getMasterPwd(), self.accountObj.secret).decode('utf-8') if self.accountObj.secret else '')
     else: # hide
         self.password.setStyleSheet("background-color: black; color: rgb(192, 0, 0);")
         self.secret.setStyleSheet("background-color: black; color: rgb(192, 0, 0);")
         self.password.setText(myGui.INFO_HIDE_TXT)
         self.secret.setPlainText(myGui.INFO_HIDE_TXT)
Esempio n. 2
0
 def changeMasterPwd(self, newPwd):
     oldPwd = config.getMasterPwd()
     conn = self.getConnection()
     mDao = MasterPwdDao(conn)
     pDao = PwdDao(conn)
     
     # 1st re-encrypt all passwords with the new master password
     accountList = pDao.getAllPwd()
     currentDate = unicode(datetime.datetime.today())
     for account in accountList:
         dePwd = util.decrypt(oldPwd, account.pwd)
         enPwd = util.encrypt(newPwd, dePwd)
         
         if account.secret:
             deSecret = util.decrypt(oldPwd, account.secret)
             enSecret = util.encrypt(newPwd, deSecret)
         else:
             enSecret = ''
         
         deUsername = util.decrypt(oldPwd, account.username)
         enUsername = util.encrypt(newPwd, deUsername)
         
         pDao.updateAccount(account.id, account.title, account.description, enUsername, enPwd, enSecret, currentDate) 
     
     # 2nd get md5 of new master password, update the masterpassword table
     newMD5String = util.md5Encoding(newPwd)
     mDao.updateMasterPwd(newMD5String)
     
     # 3rd update master password in config module
     config.setMasterPwd(newPwd)
     
     conn.commit()
     conn.close()
Esempio n. 3
0
 def addAccount(self, title, description, username, password, secret, tagIDs):
     '''
     add a user-inputed account to database
     @param title: account title
     @param description: account description
     @param username: account username
     @param password: account password
     @param secret: secret text from user
     @param tagIDs: a list of related tagIDs
     '''
     conn = self.getConnection()
     pDao = PwdDao(conn)
     
     # encrypt username & password
     mPwd = config.getMasterPwd()
     eUsername = util.encrypt(mPwd, username) if username else ''
     ePassword = util.encrypt(mPwd, password)
     eSecret = util.encrypt(mPwd, secret) if secret else ''
     currentDate = datetime.datetime.today()
     id = pDao.getAvailablePwdID()
     
     # insert
     pDao.insertAccount(id, title, description, eUsername, ePassword, eSecret, currentDate)
     
     # add tag to the new account if there is
     if len(tagIDs) > 0: pDao.setTagsOnAccount(id, tagIDs)
     
     conn.commit()
     conn.close()
Esempio n. 4
0
 def updateAccount(self, id, title, description, username, password, secret, tagIDs):
     '''
     update account
     @param id: account id
     @param title: account title
     @param description: account description
     @param username: account username
     @param password: account password, it will not be updated if value is None
     @param secret: secret text from user
     @param tagIDs: a list of related tagIDs
     '''
     
     conn = self.getConnection()
     pDao = PwdDao(conn)
     pwdObj = pDao.getPwdByID(id)
     mPwd = config.getMasterPwd()
     
     eUsername = util.encrypt(mPwd, username) if username else ''
     ePassword = util.encrypt(mPwd, password) if password else pwdObj.pwd
     eSecret = util.encrypt(mPwd, secret) if secret else ''
     currentDate = datetime.datetime.today()
     pDao.updateAccount(id, title, description, eUsername, ePassword, eSecret, currentDate)
     pDao.updateAccountTags(id, tagIDs)
     
     conn.commit()
     conn.close()
Esempio n. 5
0
 def onChg(self):
     pwdFunc = PwdFunc()
     masterFunc = MasterFunc()
     
     self.oldPwd.setFocus()
     val = self.exec_()
     if val:
         if len(unicode(self.oldPwd.text())) < 5 or len(unicode(self.oldPwd.text())) > 16:
             myGui.showErrorDialog(myGui.ERR_MASTERPWD_LEN)
             self.oldPwd.setFocus()
             self.onChg()
         elif len(unicode(self.newPwd.text())) < 5 or len(unicode(self.newPwd.text())) > 16:
             myGui.showErrorDialog(myGui.ERR_MASTERPWD_LEN)
             self.newPwd.setFocus()
             self.onChg()
         elif unicode(self.newPwd.text()) != unicode(self.newPwd2.text()):
             myGui.showErrorDialog(myGui.ERR_NEWMASTER_IDENTICAL)
             self.newPwd.clear()
             self.newPwd2.clear()
             self.newPwd.setFocus()
             self.onChg()
         elif unicode(self.oldPwd.text()) != config.getMasterPwd():
             myGui.showErrorDialog(myGui.ERR_OLDMASTER_WRONG)
             self.oldPwd.setFocus()
             self.onChg()
         else:
             masterFunc.changeMasterPwd(unicode(self.newPwd.text()))
             myGui.showInfoDialog(myGui.INFO_MASTERPWD)
Esempio n. 6
0
 def onCopyPassword(self):
     account = self.pwdFunc.getPwdByID(self.selectedPwdID)
     # decrypt password
     dePwd = util.decrypt(config.getMasterPwd(), account.pwd)
     clipboard = QtGui.QApplication.clipboard()
     clipboard.setText(dePwd)
     myGui.showInfoDialog(myGui.INFO_CLIPBOARD, account.title)
Esempio n. 7
0
 def loadData(self):
     acc = self.accountObj
     self.title.setText(acc.title)
     self.description.setPlainText(acc.description)
     self.account.setText(acc.username)
     self.secret.setPlainText(util.decrypt(config.getMasterPwd(), acc.secret).decode('utf-8') if acc.secret else '')
     tagName = [tag.name for tag in acc.tags]
     cnt = self.tags.count()
     for idx in xrange(cnt):
         if unicode(self.tags.item(idx).text()) in tagName:
             self.tags.item(idx).setSelected(True)
Esempio n. 8
0
 def decryptUsername(self, pwd):
     if pwd.username:
         pwd.username = util.decrypt(config.getMasterPwd(), pwd.username)
     return pwd