def open(self): logging.debug("opening KeePass file '%s'", self.config['kpfile']) try: self.db = kpdb.Database(self.config['kpfile'], self.config['kppass']) return True except IOError, e: raise PassWebToolException(e) return False
def get_keepass_pw(dbpath, title="", username=""): if os.path.isfile(dbpath): db = kpdb.Database( dbpath, getpass.getpass("Master password for '" + dbpath + "': ")) for entry in db.entries: if (entry.title == title) and (entry.username == username): return entry.password else: print "Error: '" + dbpath + "' does not exist." return
def _open(self,opts): 'Read a file to the in-memory database' opts,files = self.ops['open'].parse_args(opts) # fixme - add support for openning/merging multiple DBs! try: dbfile = files[0] except IndexError: six.print_(("No database file specified")) sys.exit(1) self.db = kpdb.Database(files[0],opts.masterkey) self.hier = self.db.hierarchy() return
def _reload(self, password): LOG.debug('Loading %s' % self._db_file) self._db = kpdb.Database(self._db_file, password) self._root = self._db.hierarchy() self._db_mtime = os.path.getmtime(self._db_file)
#!/usr/bin/env python import sys, os try: from keepass import kpdb except ImportError: path = os.path.dirname(os.path.dirname(__file__)) path = os.path.join('python') sys.path.append(path) from keepass import kpdb filename = sys.argv[1] masterkey = sys.argv[2] db = kpdb.Database(filename, masterkey) print db
#!/usr/bin/env python import sys, os try: from keepass import kpdb except ImportError: path = os.path.dirname(os.path.dirname(__file__)) path = os.path.join('python') sys.path.append(path) from keepass import kpdb filename = sys.argv[1] masterkey = sys.argv[2] db = kpdb.Database(masterkey, filename) db.header.dwGroups = 0 db.header.dwEntries = 0 buf = db.header.encode() filename2 = os.path.splitext(filename) filename2 = filename2[0] + '2' + filename2[1] print 'Writing:', filename2 fp = open(filename2, "w") fp.write(buf) fp.close() db2 = kpdb.Database(masterkey, filename2) print db2
def open_database(self, passphrase): try: kdb = kpdb.Database(self.database_path, passphrase) self.database = kdb except ValueError: raise WrongPassword("Incorrect password")