Skip to content

Commit

Permalink
Add credentials creation script
Browse files Browse the repository at this point in the history
  • Loading branch information
simonwoerpel committed Nov 2, 2023
1 parent 1efc7fd commit 9bf4b19
Show file tree
Hide file tree
Showing 2 changed files with 96 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
fs_logins.csv
.htpasswd
cache.db*
farmsubsidy.duckdb
data

Expand Down
93 changes: 93 additions & 0 deletions generate_logins.ipynb
Original file line number Diff line number Diff line change
@@ -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
}

0 comments on commit 9bf4b19

Please sign in to comment.