Skip to content

Commit

Permalink
update File IO
Browse files Browse the repository at this point in the history
  • Loading branch information
rambasnet committed Nov 6, 2024
1 parent 8304f43 commit b8372ff
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 36 deletions.
1 change: 1 addition & 0 deletions demos/users.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# list of players information
- email: [email protected]
lost: 2
name: John Doe
Expand Down
53 changes: 17 additions & 36 deletions notebooks/Ch10-1-Files.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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']= '[email protected]'\n",
"new_user['password']= hashed_password\n",
"new_user['salt']= salt\n",
"new_user['name'] = 'Michael Jordan'\n",
"new_user['email'] = '[email protected]'\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': '[email protected]',\n",
" 'password': 'password',\n",
" 'played': 10,\n",
" 'lost': 2},\n",
" {'name': 'Jane Doe',\n",
" 'email': '[email protected]',\n",
" 'password': 'password123',\n",
" 'played': 5,\n",
" 'lost': 1},\n",
" {'name': 'Michael Jordan',\n",
" 'email': '[email protected]',\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': '[email protected]', 'password': 'password', 'played': 10, 'lost': 2}, {'name': 'Jane Doe', 'email': '[email protected]', 'password': 'password123', 'played': 5, 'lost': 1}, {'name': 'Michael Jordan', 'email': '[email protected]', 'password': 'bc0951eff5171243056cd7a3a073ba8b2366a8230c997c5fac8cd3052d20fcec', 'salt': 'PJLLqVpW4qpa1hIu', 'played': 20, 'lost': 5}, {'name': 'Michael Jordan', 'email': '[email protected]', 'password': 'AFE4AD9E6FF039DCD90C82705C94AC3EB231AB6B8045D2B1B519640DA8518B22', 'salt': 'MPWAcxbAyiVXdpeU', 'played': 20, 'lost': 5}]\n"
]
}
],
"source": [
Expand Down

0 comments on commit b8372ff

Please sign in to comment.