Exemple #1
0
def setMainPswd(new, old):
    encOldPswd = helpers.encMainPswd(old)
    encNewPswd = helpers.encMainPswd(new)
    resp = helpers.resetMainPswd(helpers.getUname(), encOldPswd, encNewPswd)
    if resp != "success":
        return resp
    passwords = helpers.getPswdsDoc(helpers.getUname(), encNewPswd)
    if type(passwords) != dict:
        return passwords
    serviceList = getAllServicesFromDoc(old, passwords)
    serviceToPass = {}
    for service in serviceList:
        key = helpers.sha256(service)
        encrypted = passwords[key]
        decrypted = {
            key: helpers.dencPswd(service, value, old)
            for key, value in encrypted.items()
        }
        serviceToPass[service] = decrypted
    encServiceList = []
    for service in serviceList:
        encPswd = {
            key: helpers.encPswd(service, value, new)
            for key, value in serviceToPass[service].items()
        }
        passwords[helpers.sha256(service)] = encPswd
        encService = helpers.encService(service, new)
        encServiceList.append(encService)
    passwords[helpers.sha256("service list")] = encServiceList
    return helpers.setPswdsDoc(helpers.getUname(), encNewPswd, passwords)
Exemple #2
0
    def del_account(self):
        mainPswd = self.layoutOptions[self.screen].children()[8].text()
        if len(mainPswd) == 0:
            alert("You must input your main password")
        else:
            uname = helpers.getUname()
            resp = helpers.checkMainPswd(uname, helpers.encMainPswd(mainPswd))
            if resp == "failure":
                alert("That is not the correct main password")
            elif resp == "user not in database":
                alert(
                    f"The username {uname} does not have an account associated with it"
                )
            else:
                if self.ask(
                        """Are you absolutely sure that you want to delete this account?

Any passwords that you have stored will no longer be accesable.

Only click yes if you are absolutely sure that you understand the consequences of doing so"""
                ):
                    helpers.dropUser(uname, helpers.encMainPswd(mainPswd))
                    helpers.delUname()
                    alert("Your account has been deleted")
                    self.on_changed("Login")
                else:
                    alert("Your account has not been deleted")
Exemple #3
0
def getAllServices(mainPswd):
    encMainPswd = helpers.encMainPswd(mainPswd)
    encServiceList = helpers.getServices(helpers.getUname(), encMainPswd)
    if type(encServiceList) != list:
        return encServiceList
    serviceList = set()
    for encService in encServiceList:
        decrypted = helpers.dencService(encService, mainPswd)
        serviceList.add(decrypted)
    return list(serviceList)
Exemple #4
0
def getPswd(service, mainPswd):
    encMainPswd = helpers.encMainPswd(mainPswd)
    resp = helpers.getPswd(helpers.getUname(), encMainPswd,
                           helpers.sha256(service))
    try:
        return {
            key: helpers.dencPswd(service, value, mainPswd)
            for key, value in resp.items()
        }
    except:
        return resp
Exemple #5
0
def setPswd(service, mainPswd, pswd=None, uname=None):
    encService = helpers.encService(service, mainPswd)
    encMainPswd = helpers.encMainPswd(mainPswd)
    encPswd = helpers.encPswd(service, pswd, mainPswd)
    if uname:
        encUname = helpers.encPswd(service, uname, mainPswd)
        return helpers.setPswd(helpers.getUname(), encMainPswd,
                               helpers.sha256(service), {
                                   "pswd": encPswd,
                                   "uname": encUname
                               }, encService)
    return helpers.setPswd(helpers.getUname(), encMainPswd,
                           helpers.sha256(service), {"pswd": encPswd},
                           encService)
Exemple #6
0
def delPswd(service, mainPswd):
    encMainPswd = helpers.encMainPswd(mainPswd)
    encService = helpers.encService(service, mainPswd)
    encServiceList = helpers.getServices(helpers.getUname(), encMainPswd)
    if type(encServiceList) != list:
        return encServiceList
    serviceList = set()
    toSet = []
    for encService in encServiceList:
        dencService = helpers.dencService(encService, mainPswd)
        if dencService != service:
            serviceList.add(dencService)
    for dencService in serviceList:
        toSet.append(helpers.encService(dencService, mainPswd))
    resp = helpers.setServiceList(helpers.getUname(), encMainPswd, toSet)
    if resp != "success":
        return resp
    return helpers.delPswd(helpers.getUname(), encMainPswd,
                           helpers.sha256(service))
Exemple #7
0
def checkMainPswd(mainPswd):
    return helpers.checkMainPswd(helpers.getUname(),
                                 helpers.encMainPswd(mainPswd))
Exemple #8
0
 def on_button_clicked(self):
     chils = self.layoutOptions[self.screen].children()
     if self.screen == "Login":
         global MAIN_PSWD, timer
         if len(chils) == 4:
             uname = chils[2].text()
             if len(uname) == 0:
                 alert("You must input your username!")
             else:
                 mainPswd = chils[3].text()
                 if helpers.userExists(uname):
                     if len(mainPswd) == 0:
                         alert("You must input your main password!")
                     else:
                         resp = helpers.checkMainPswd(
                             uname, helpers.encMainPswd(mainPswd))
                         if resp == "failure":
                             alert("That is not the correct main password")
                             chils[3].setText("")
                         else:
                             helpers.setUname(uname)
                             MAIN_PSWD = mainPswd
                             if timer:
                                 timer.stop()
                             timer = QTimer()
                             timer.timeout.connect(self.logout)
                             timer.start(90000)
                             self.on_changed("Manage passwords")
                 else:
                     alert(
                         f"The username {uname} does not have an account associated with it"
                     )
                     chils[2].setText("")
         else:
             uname = chils[3].text()
             p1 = chils[4].text()
             p2 = chils[5].text()
             if p1 != p2:
                 alert("The two passwords don't match")
                 chils[4].setText("")
                 chils[5].setText("")
             elif len(p1) == 0:
                 alert("You must input a main password")
             elif helpers.userExists(uname):
                 alert(f"The username {uname} is already in use")
             else:
                 helpers.createUser(uname, helpers.encMainPswd(p1))
                 helpers.setUname(uname)
                 MAIN_PSWD = p1
                 if timer:
                     timer.stop()
                 timer = QTimer()
                 timer.timeout.connect(self.logout)
                 timer.start(90000)
                 alert("Your account has been created")
                 self.on_changed("Manage passwords")
     elif self.screen == "Manage passwords":
         global SERVICES
         service = chils[1].text()
         pswd = getPswd(service.lower(), MAIN_PSWD)
         if pswd == "password doesn't exist":
             lyt = chils[2].widget().layout()
             for i in range(lyt.count()):
                 widget = lyt.takeAt(i).widget()
                 if isinstance(widget, QLabel):
                     service = widget.text()[2:]
                     pswd = getPswd(service.lower(), MAIN_PSWD)
                     self.options(service, pswd)
                     return
             if self.ask(
                     f"Would you like to set a username for {service}?"):
                 uname, okPressed = QInputDialog.getText(
                     self, "Set username",
                     f"Username to set for {service}:", QLineEdit.Normal,
                     "")
                 if okPressed:
                     if len(uname) > 0:
                         pswd, okPressed = QInputDialog.getText(
                             self, "Set password",
                             f"Password to set for {service}:",
                             QLineEdit.Normal, "")
                         if okPressed:
                             if len(pswd) > 0:
                                 resp = setPswd(service.lower(),
                                                MAIN_PSWD,
                                                pswd=pswd,
                                                uname=uname)
                                 if resp == "success":
                                     alert(
                                         f"Username for {service} successfully set to {uname} and password set to {pswd}"
                                     )
                                 else:
                                     alert(
                                         "There was a problem setting your password"
                                     )
                                 SERVICES = getAllServices(MAIN_PSWD)
                                 self.layoutOptions[
                                     self.screen].children()[1].setText("")
                             else:
                                 alert("You must enter a password")
                     else:
                         alert("You must enter a username")
             else:
                 pswd, okPressed = QInputDialog.getText(
                     self, "Set password",
                     f"Password to set for {service}:", QLineEdit.Normal,
                     "")
                 if okPressed:
                     if len(pswd) > 0:
                         resp = setPswd(service.lower(),
                                        MAIN_PSWD,
                                        pswd=pswd)
                         if resp == "success":
                             alert(
                                 f"Password for {service} successfully set to {pswd}"
                             )
                         else:
                             alert(
                                 "There was a problem setting your password"
                             )
                         SERVICES = getAllServices(MAIN_PSWD)
                         self.layoutOptions[
                             self.screen].children()[1].setText("")
                     else:
                         alert("You must enter a password")
         else:
             self.options(service, pswd)
     elif self.screen == "Reset main password":
         mainPswd = chils[2].text()
         p1 = chils[4].text()
         p2 = chils[6].text()
         if len(mainPswd) == 0:
             alert("You must enter your current password")
         elif p1 != p2:
             alert("The two passwords don't match!")
         elif len(p1) == 0:
             alert("You must enter a new password")
         else:
             resp = checkMainPswd(mainPswd)
             if resp == "failure":
                 alert("That's not your old password")
                 chils[2].setText("")
             elif resp == "user not in database":
                 alert(
                     f"The username {mainPswd} does not have an account associated with it"
                 )
             elif self.ask(
                     "Are you absolutely sure that you want to reset your main password?"
             ):
                 resp = setMainPswd(p1, mainPswd)
                 if resp == "success":
                     alert(f"Password set to {p1}")
                     for item in chils:
                         if isinstance(item, QLineEdit):
                             item.setText("")
                 else:
                     alert(
                         "There was a problem resetting your main password")
             else:
                 alert("Your password was not reset")