A mirror of my website's source code.

By using this site, you agree to have cookies stored on your device, strictly for functional purposes, such as storing your session and preferences.

Dismiss

 How-to-Store-Passwords.html

View raw Download
text/html • 5.22 kiB
HTML document, ASCII text, with very long lines (423)
        
            
1
<!DOCTYPE html>
2
<html lang="en">
3
4
<head>
5
6
7
<meta charset="UTF-8" />
8
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
9
<title>How to Store a Passwords - S0G</title>
10
<link rel="stylesheet" href="/src/global.css" />
11
12
<link rel="stylesheet" href="/src/pygments-friendly.css" />
13
<link rel="stylesheet" href="/src/blog.css" />
14
15
</head>
16
17
<body>
18
<header>
19
<h2><a href="/">Steve0Greatness</a></h2>
20
<nav>
21
<a href="/blog">Blog</a>
22
<a href="/link-tree.html">Link Tree</a>
23
</nav>
24
</header>
25
26
<ol role="navigation" class="breadcrumbs" aria-roledescription="Site breadcrumb">
27
<li>
28
<a href="/">Index</a>
29
</li>
30
31
<li >
32
<a href="/blog">
33
Blog Index
34
</a>
35
</li>
36
37
<li aria-current="location">
38
39
How to Store a Passwords
40
41
</li>
42
43
</ol>
44
<main>
45
<article>
46
<header>
47
<h2 id="blog-post-titled">How to Store a Passwords</h2>
48
<div role="toolbar" class="toolbar">
49
<a href="https://toot.kytta.dev/?text=Take a look at this article by @S0G@mastodon.social: https://steve0greatness.github.io/blog/How-to-Store-Passwords.html" title="Share to Mastodon">
50
<img src="/toot-kytta-dev-icon.svg" width="16" height="16" aria-hidden="true" title="Share to Mastodon" />
51
</a>
52
<a href="/blog/How-to-Store-Passwords.html" title="Direct link">
53
<span aria-hidden="true">
54
&#128279;
55
</span>
56
</a>
57
<a href="/blog/How-to-Store-Passwords.txt" title="Markdown source">
58
<img src="/md-src.svg" width="16" height="16" />
59
</a>
60
</div>
61
<time>2023 Nov 2</time>
62
</header>
63
<p><strong>Disclaimer</strong>: The world of cyber-security is an incredibly complex and constantly evolving topic, and I am not a cyber-security researcher; I create projects for fun.</p>
64
65
<p>Storing a password in a server can be intimidating. Password management is incredibly tricky, as anything you mess up could compromise your users' password(s). Thankfully, random websites you've never visited before have a pure HTML blog post from 2023 about that exact topic, and how to do it properly.</p>
66
67
<p>Basically, it's just this sequence of steps:</p>
68
69
<ul>
70
<li>Generate a long random sequence of characters, this is called a <em><a href="https://en.wikipedia.org/wiki/Salt_(cryptography)">salt</a></em>(generate for each user, do not use a master salt)</li>
71
<li>Prepend(or append, it doesn't matter, just keep it consistent) this to the user's password</li>
72
<li>Use a <a href="https://en.wikipedia.org/wiki/Hash_function">hashing algorithm</a>, such as <a href="https://en.wikipedia.org/wiki/PBKDF2">PBKDF2</a>, to generate a unique sequence of characters that will uniquely identify that password.</li>
73
<li>Store the salt and hash in the same place, <em>do not</em> store the password on it's own.</li>
74
</ul>
75
76
<p>And to check if a password is right, repeat the steps, except rather than generating a random sequence of characters, get the sequence of characters that you've stored along with the hash.</p>
77
78
<h2 id="why-do-this">Why Do <em>This</em>?</h2>
79
80
<p>You might be thinking: <em>That's a bit arbitrary innit?</em> And if you aren't then you can stop reading now.</p>
81
82
<p>This method of storing passwords is the only way to ensure that you are securely storing them. So let's go through some other ways, and why they aren't so good.</p>
83
84
<h3 id="plaintext-passwords">Plaintext Passwords</h3>
85
86
<p>Storing your passwords in plaintext allows anyone who can get into your server to easily take any password they want, as no matter how good your users' password is, their account will be hacked if an unauthorized or malicious individual is able to get in.</p>
87
88
<h3 id="encrypted-passwords">Encrypted Passwords</h3>
89
90
<p>This is basically just plaintext with additional steps. As long as your master-key is stored somewhere, it will get stolen as soon as somebody manages to get into your system.</p>
91
92
<h3 id="bare-hashing">Bare Hashing</h3>
93
94
<p>A hash isn't able to be undone, meaning theoretically you should be able to <em>just</em> hash your password. This, while a fair assumption, has unfortunately been incorrect for quite some time. There are databases online that store every word in the english language(or just some words) in addition to common passwords and their hashes, and users will often use words for their passwords, even though it's insecure.</p>
95
96
<p>This is where salts come in. Due to the nature of hashes, even a single change in a string will entirely change it's hash, as such, if you add a random sequence of characters to a string, then you can entirely change it's hash.</p>
97
98
</article>
99
</main>
100
<footer role="group">
101
<div class="footer-link-list-holder">
102
<span aria-hidden="true" id="footer-label-social-accounts" class="footer-link-list-label">Social Accounts</span>
103
<ol class="footer-link-list" aria-labelledby="footer-label-social-accounts">
104
<li><a href="https://mastodon.social/@S0G" rel="me">Mastodon</a></li>
105
<li><a href="https://youtube.com/@s0g">YouTube</a></li>
106
</ol>
107
</div>
108
</footer>
109
</body>
110
111
</html>