|
1822 | 1822 | },
|
1823 | 1823 | {
|
1824 | 1824 | "cell_type": "code",
|
1825 |
| - "execution_count": 16, |
| 1825 | + "execution_count": 32, |
1826 | 1826 | "metadata": {},
|
1827 | 1827 | "outputs": [],
|
1828 | 1828 | "source": [
|
1829 | 1829 | "def get_hashed_password(password, salt):\n",
|
1830 | 1830 | " import hashlib\n",
|
1831 |
| - " return hashlib.sha256((password + salt).encode('utf-8')).hexdigest()" |
| 1831 | + " round = 100_000\n", |
| 1832 | + " return hashlib.pbkdf2_hmac('sha256', password.encode('utf-8'), salt.encode('utf-8'), round).hex().upper()" |
1832 | 1833 | ]
|
1833 | 1834 | },
|
1834 | 1835 | {
|
1835 | 1836 | "cell_type": "code",
|
1836 |
| - "execution_count": 17, |
| 1837 | + "execution_count": null, |
1837 | 1838 | "metadata": {},
|
1838 | 1839 | "outputs": [
|
1839 | 1840 | {
|
1840 | 1841 | "name": "stdout",
|
1841 | 1842 | "output_type": "stream",
|
1842 | 1843 | "text": [
|
1843 |
| - "salt = 'PJLLqVpW4qpa1hIu'\n", |
1844 |
| - "hashed_password = 'bc0951eff5171243056cd7a3a073ba8b2366a8230c997c5fac8cd3052d20fcec'\n" |
| 1844 | + "salt = 'MPWAcxbAyiVXdpeU'\n", |
| 1845 | + "hashed_password = 'AFE4AD9E6FF039DCD90C82705C94AC3EB231AB6B8045D2B1B519640DA8518B22'\n" |
1845 | 1846 | ]
|
1846 | 1847 | }
|
1847 | 1848 | ],
|
1848 | 1849 | "source": [
|
1849 |
| - "import hashlib\n", |
1850 |
| - "\n", |
1851 | 1850 | "salt = get_random_salt()\n",
|
1852 | 1851 | "print(f'{salt = }')\n",
|
1853 | 1852 | "salted_password = 'P@ssw0rd'+salt\n",
|
|
1857 | 1856 | },
|
1858 | 1857 | {
|
1859 | 1858 | "cell_type": "code",
|
1860 |
| - "execution_count": null, |
| 1859 | + "execution_count": 34, |
1861 | 1860 | "metadata": {},
|
1862 | 1861 | "outputs": [],
|
1863 | 1862 | "source": [
|
1864 | 1863 | "# create a new player\n",
|
1865 | 1864 | "new_user = {}\n",
|
1866 |
| - "new_user['name']= 'Michael Jordan'\n", |
1867 |
| - "new_user['email']= ' [email protected]'\n", |
1868 |
| - "new_user['password']= hashed_password\n", |
1869 |
| - "new_user['salt']= salt\n", |
| 1865 | + "new_user['name'] = 'Michael Jordan'\n", |
| 1866 | + "new_user['email'] = ' [email protected]'\n", |
| 1867 | + "new_user['password'] = hashed_password\n", |
| 1868 | + "new_user['salt'] = salt\n", |
1870 | 1869 | "new_user['played'] = 20\n",
|
1871 | 1870 | "new_user['lost'] = 5"
|
1872 | 1871 | ]
|
1873 | 1872 | },
|
1874 | 1873 | {
|
1875 | 1874 | "cell_type": "code",
|
1876 |
| - "execution_count": null, |
| 1875 | + "execution_count": 35, |
1877 | 1876 | "metadata": {},
|
1878 | 1877 | "outputs": [
|
1879 | 1878 | {
|
1880 |
| - "data": { |
1881 |
| - "text/plain": [ |
1882 |
| - "[{'name': 'John Doe',\n", |
1883 |
| - " 'email': ' [email protected]',\n", |
1884 |
| - " 'password': 'password',\n", |
1885 |
| - " 'played': 10,\n", |
1886 |
| - " 'lost': 2},\n", |
1887 |
| - " {'name': 'Jane Doe',\n", |
1888 |
| - " 'email': ' [email protected]',\n", |
1889 |
| - " 'password': 'password123',\n", |
1890 |
| - " 'played': 5,\n", |
1891 |
| - " 'lost': 1},\n", |
1892 |
| - " {'name': 'Michael Jordan',\n", |
1893 |
| - " 'email': ' [email protected]',\n", |
1894 |
| - " 'password': 'bc0951eff5171243056cd7a3a073ba8b2366a8230c997c5fac8cd3052d20fcec',\n", |
1895 |
| - " 'salt': 'PJLLqVpW4qpa1hIu',\n", |
1896 |
| - " 'played': 20,\n", |
1897 |
| - " 'lost': 5}]" |
1898 |
| - ] |
1899 |
| - }, |
1900 |
| - "execution_count": 23, |
1901 |
| - "metadata": {}, |
1902 |
| - "output_type": "execute_result" |
| 1879 | + "name": "stdout", |
| 1880 | + "output_type": "stream", |
| 1881 | + "text": [ |
| 1882 | + "[{'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" |
| 1883 | + ] |
1903 | 1884 | }
|
1904 | 1885 | ],
|
1905 | 1886 | "source": [
|
|
0 commit comments