From b8372ff9e8e7c2e7f7a7ba3e76e568bcef785ebe Mon Sep 17 00:00:00 2001 From: Ram Basnet Date: Wed, 6 Nov 2024 15:41:00 -0700 Subject: [PATCH] update File IO --- demos/users.yaml | 1 + notebooks/Ch10-1-Files.ipynb | 53 ++++++++++++------------------------ 2 files changed, 18 insertions(+), 36 deletions(-) diff --git a/demos/users.yaml b/demos/users.yaml index 214aba8..36242e8 100644 --- a/demos/users.yaml +++ b/demos/users.yaml @@ -1,3 +1,4 @@ +# list of players information - email: jdoe@gmail.com lost: 2 name: John Doe diff --git a/notebooks/Ch10-1-Files.ipynb b/notebooks/Ch10-1-Files.ipynb index 1d63240..5e23588 100644 --- a/notebooks/Ch10-1-Files.ipynb +++ b/notebooks/Ch10-1-Files.ipynb @@ -1822,32 +1822,31 @@ }, { "cell_type": "code", - "execution_count": 16, + "execution_count": 32, "metadata": {}, "outputs": [], "source": [ "def get_hashed_password(password, salt):\n", " import hashlib\n", - " return hashlib.sha256((password + salt).encode('utf-8')).hexdigest()" + " round = 100_000\n", + " return hashlib.pbkdf2_hmac('sha256', password.encode('utf-8'), salt.encode('utf-8'), round).hex().upper()" ] }, { "cell_type": "code", - "execution_count": 17, + "execution_count": null, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - "salt = 'PJLLqVpW4qpa1hIu'\n", - "hashed_password = 'bc0951eff5171243056cd7a3a073ba8b2366a8230c997c5fac8cd3052d20fcec'\n" + "salt = 'MPWAcxbAyiVXdpeU'\n", + "hashed_password = 'AFE4AD9E6FF039DCD90C82705C94AC3EB231AB6B8045D2B1B519640DA8518B22'\n" ] } ], "source": [ - "import hashlib\n", - "\n", "salt = get_random_salt()\n", "print(f'{salt = }')\n", "salted_password = 'P@ssw0rd'+salt\n", @@ -1857,49 +1856,31 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 34, "metadata": {}, "outputs": [], "source": [ "# create a new player\n", "new_user = {}\n", - "new_user['name']= 'Michael Jordan'\n", - "new_user['email']= 'jordan@gmail.com'\n", - "new_user['password']= hashed_password\n", - "new_user['salt']= salt\n", + "new_user['name'] = 'Michael Jordan'\n", + "new_user['email'] = 'jordan@gmail.com'\n", + "new_user['password'] = hashed_password\n", + "new_user['salt'] = salt\n", "new_user['played'] = 20\n", "new_user['lost'] = 5" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 35, "metadata": {}, "outputs": [ { - "data": { - "text/plain": [ - "[{'name': 'John Doe',\n", - " 'email': 'jdoe@gmail.com',\n", - " 'password': 'password',\n", - " 'played': 10,\n", - " 'lost': 2},\n", - " {'name': 'Jane Doe',\n", - " 'email': 'jane@gmail.com',\n", - " 'password': 'password123',\n", - " 'played': 5,\n", - " 'lost': 1},\n", - " {'name': 'Michael Jordan',\n", - " 'email': 'jordan@gmail.com',\n", - " 'password': 'bc0951eff5171243056cd7a3a073ba8b2366a8230c997c5fac8cd3052d20fcec',\n", - " 'salt': 'PJLLqVpW4qpa1hIu',\n", - " 'played': 20,\n", - " 'lost': 5}]" - ] - }, - "execution_count": 23, - "metadata": {}, - "output_type": "execute_result" + "name": "stdout", + "output_type": "stream", + "text": [ + "[{'name': 'John Doe', 'email': 'jdoe@gmail.com', 'password': 'password', 'played': 10, 'lost': 2}, {'name': 'Jane Doe', 'email': 'jane@gmail.com', 'password': 'password123', 'played': 5, 'lost': 1}, {'name': 'Michael Jordan', 'email': 'jordan@gmail.com', 'password': 'bc0951eff5171243056cd7a3a073ba8b2366a8230c997c5fac8cd3052d20fcec', 'salt': 'PJLLqVpW4qpa1hIu', 'played': 20, 'lost': 5}, {'name': 'Michael Jordan', 'email': 'jordan@gmail.com', 'password': 'AFE4AD9E6FF039DCD90C82705C94AC3EB231AB6B8045D2B1B519640DA8518B22', 'salt': 'MPWAcxbAyiVXdpeU', 'played': 20, 'lost': 5}]\n" + ] } ], "source": [