Created
August 15, 2021 08:33
-
-
Save andfanilo/4bd880ea760d67d5afc40d215ef060e1 to your computer and use it in GitHub Desktop.
Streamlit keepass browser
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| """ | |
| PS: all password entries are in cleartext between server and browser, DO NOT DEPLOY THIS ON A SERVER. EVER. | |
| """ | |
| from io import BufferedReader | |
| from typing import Any | |
| import streamlit as st | |
| from construct import Container | |
| from pykeepass import PyKeePass | |
| from pykeepass.exceptions import CredentialsError | |
| def _ignore_hash(_: Any): | |
| return None | |
| @st.cache(hash_funcs={BufferedReader: _ignore_hash, Container: _ignore_hash}) | |
| def _load_db(path: str, pwd: str) -> PyKeePass: | |
| return PyKeePass(path, pwd) | |
| def main(): | |
| st.title("Keepass browser") | |
| with st.sidebar: | |
| st.header("Configuration") | |
| with st.form(key="my_form"): | |
| path = st.text_input("Path to kdbx file: ") | |
| pwd = st.text_input("Enter Password: ", type="password") | |
| st.form_submit_button(label="Submit") | |
| n_cols = st.number_input("Number of columns", 2, 8, 4) | |
| if path == "" or pwd == "": | |
| st.warning("Please enter credentials") | |
| return | |
| try: | |
| kp = _load_db(path, pwd) | |
| all_entries = sorted(kp.entries, key=lambda e: e.title.upper()) | |
| n_rows = 1 + len(all_entries) // int(n_cols) | |
| rows = [st.container() for _ in range(n_rows)] | |
| cols_per_row = [r.columns(n_cols) for r in rows] | |
| for element_index, element in enumerate(all_entries): | |
| with rows[element_index // n_cols]: | |
| cols_per_row[element_index // n_cols][element_index % n_cols].subheader( | |
| element.title | |
| ) | |
| if element.password is not None and 'Hello world' in element.password: # red flag for certain pattern | |
| cols_per_row[element_index // n_cols][element_index % n_cols].error( | |
| f"{element.username} - {element.password}" | |
| ) | |
| else: | |
| cols_per_row[element_index // n_cols][element_index % n_cols].markdown( | |
| f"{element.username} - {element.password}" | |
| ) | |
| except (FileNotFoundError, AttributeError): | |
| st.error("Could not find KDBX file") | |
| except CredentialsError: | |
| st.error("Wrong password") | |
| if __name__ == "__main__": | |
| st.set_page_config( | |
| page_title="Streamlit Keepass Browser", page_icon=":lock:", layout="wide" | |
| ) | |
| main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment