From 9bf4b19787d552b846026ff53ce2b69c50002bad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Simon=20W=C3=B6rpel?= Date: Thu, 2 Nov 2023 14:40:06 +0100 Subject: [PATCH] Add credentials creation script --- .gitignore | 3 ++ generate_logins.ipynb | 93 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 96 insertions(+) create mode 100644 generate_logins.ipynb diff --git a/.gitignore b/.gitignore index 4b8678c..7765207 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,6 @@ +fs_logins.csv +.htpasswd +cache.db* farmsubsidy.duckdb data diff --git a/generate_logins.ipynb b/generate_logins.ipynb new file mode 100644 index 0000000..355bdd6 --- /dev/null +++ b/generate_logins.ipynb @@ -0,0 +1,93 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": null, + "id": "ab5ea961-0ab0-4cf5-bcb3-fc0c99af0055", + "metadata": {}, + "outputs": [], + "source": [ + "import pandas as pd\n", + "import shortuuid\n", + "import bcrypt" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "e9308c8d-4b57-4ca8-989d-f05fe3860ae3", + "metadata": {}, + "outputs": [], + "source": [ + "HTPASSWD = \".htpasswd\"\n", + "CLEARFILE = \"fs_logins.csv\"\n", + "PREFIX = \"farmsubsidy\"" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "acd0247c-afac-4de7-916d-e1efc9f3a9d0", + "metadata": {}, + "outputs": [], + "source": [ + "def generate_logins(start, end, prefix):\n", + " for i in range(start, end):\n", + " pw = shortuuid.uuid()[:12]\n", + " hashed = bcrypt.hashpw(pw.encode(), bcrypt.gensalt()).decode()\n", + " yield f\"{prefix}-{str(i).zfill(4)}\", hashed, pw" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "a018fa38-86b2-4397-b176-d72d039210c8", + "metadata": {}, + "outputs": [], + "source": [ + "df = pd.DataFrame(generate_logins(0, 100, PREFIX), columns=(\"username\", \"hashed\", \"password\"))\n", + "df.head()" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "e64ac6f1-5148-472e-8824-0cc6644aa3b7", + "metadata": {}, + "outputs": [], + "source": [ + "df[[\"username\", \"password\"]].to_csv(CLEARFILE, index=False)\n", + "df[[\"username\", \"hashed\"]].to_csv(HTPASSWD, index=False, header=False, sep=\":\")" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "c49f125a-f41d-413a-8315-ad4d11d05164", + "metadata": {}, + "outputs": [], + "source": [] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3 (ipykernel)", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.10.9" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +}