示例#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)
示例#2
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)
示例#3
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")
示例#4
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)
示例#5
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))
示例#6
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
示例#7
0
def checkMainPswd(mainPswd):
    return helpers.checkMainPswd(helpers.getUname(),
                                 helpers.encMainPswd(mainPswd))
示例#8
0
    def on_changed(self, value):
        if value == "Manage passwords":
            global SERVICES
            s1 = getAllServices(MAIN_PSWD)
            s1 = list({service.title() for service in s1})
            s1.sort()
            lyt = self.layoutOptions[value].children()[2].widget().layout()
            if s1 != SERVICES:
                SERVICES = s1
                SERVICES = list({service.title() for service in SERVICES})
                SERVICES.sort()
                for i in reversed(range(lyt.count())):
                    widget = lyt.takeAt(i).widget()
                    if widget is not None:
                        widget.setParent(None)
                for service in SERVICES:
                    label = QLabel("• " + service)

                    def on_click(s, e):
                        pswd = getPswd(s.lower(), MAIN_PSWD)
                        self.options(s, pswd)

                    label.mouseReleaseEvent = partial(on_click, service)
                    lyt.addWidget(label)
        if self.screen == "Login" and self.screen != value:
            self.screenChoice.show()
        elif value == "Login":
            self.screenChoice.hide()
            if self.screen != value:
                self.mainLayout.removeWidget(self.layoutOptions["Login"])
                sip.delete(self.layoutOptions["Login"])
                if self.screen != "My account":
                    self.mainLayout.removeWidget(self.go_button)
                self.layoutOptions["Login"] = make_login_lyt()
                self.layoutOptions["Login"].children(
                )[3].returnPressed.connect(self.on_button_clicked)
                self.layoutOptions["Login"].children()[1].stateChanged.connect(
                    self.checkbox_clicked)
                self.mainLayout.addWidget(self.layoutOptions["Login"])
                if self.screen != "My account":
                    self.mainLayout.addWidget(self.go_button)
        if self.screen == "My account":
            self.go_button = QPushButton("Go!")
            self.go_button.clicked.connect(self.on_button_clicked)
            self.go_button.setAutoDefault(True)
            self.mainLayout.addWidget(self.go_button)
        elif value == "My account":
            self.mainLayout.removeWidget(self.go_button)
            sip.delete(self.go_button)
        for key in self.layoutOptions:
            if key != value:
                self.layoutOptions[key].hide()
        self.layoutOptions[value].show()
        self.screen = value
        if value == "Login" and self.screen != value:
            self.checkbox_clicked(Qt.Checked)
            self.checkbox_clicked(Qt.Unchecked)
        chils = self.layoutOptions[value].children()
        for item in chils:
            if isinstance(item, QLineEdit):
                item.setText("")
        uname = helpers.getUname()
        if uname != "file does not exist" and value == "Login" and chils[
                1].isChecked() == False:
            self.layoutOptions[value].children()[2].setText(uname)