def generate_master_password_check(self, master_password): self.storage.lock.acquire() pid = 0 password = Password() if self.check_master_password(master_password) != -1: for key,item in self.database['passwords'].items(): if item.special and item.mark == "MasterPasswordCheck": pid = item.id password.sync_code = "M" break else: self.database['passwords_num'] += 1 pid = self.database['passwords_num'] password.sync_code = "A" password.id = pid password.special = True password.mark = "MasterPasswordCheck" password.intro = self.calculate_key(master_password, password) self.database['passwords'][str(pid)] = password self.storage.save() self.storage.lock.release()
def do(self, args): if args.operate == "add" or args.operate == "a": password = Password() password.mark = str(args.mark) if args.url: password.url = str(args.url) if args.intro: password.intro = str(args.intro) if args.release: password.version = int(args.release) if args.length: password.length = int(args.length) if args.type: password.type = args.type if args.no_password or self.config.get("option", "add_without_mpw") == "1": self.daemon.add(password) return master_password = getpass.getpass("Please input your master password:"******"option", "mpw_check") == "1": if self.daemon.check_master_password(master_password) != 1: print("Master Password Error. Please check or set your master password.") return pw_id = self.daemon.add(password) result = self.daemon.get(master_password, [pw_id]) self.print_password(result) return if args.operate == "del" or args.operate == "d": self.daemon.remove(args.id) return if args.operate == "ls" or args.operate == "l": if not args.mark: keyword = "" else: keyword = args.mark passwords = self.daemon.search(keyword) passwords = self.daemon.get("", [value.id for value in passwords]) self.print_password(passwords, keyword, False) return if args.operate == "get" or args.operate == "g": master_password = getpass.getpass("Please input your master password:"******"option", "mpw_check") == "1": if self.daemon.check_master_password(master_password) != 1: print("Master Password Error. Please check or set your master password.") return if not args.mark: keyword = "" else: keyword = args.mark passwords = self.daemon.search(keyword) passwords = self.daemon.get(master_password, [value.id for value in passwords]) self.print_password(passwords, keyword, True) return if not args.operate: if args.set_master_password: master_password = getpass.getpass("Please input your master password:"******"Please retype your master password:"******"Password didn't match. Please try again.") return self.daemon.generate_master_password_check(master_password) return