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 • 6.2 kiB
HTML document, ASCII text, with very long lines (423)
        
            
1
<!DOCTYPE html>
2
<html lang="en-us" prefix="og: https://ogp.me/ns#">
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
<meta property="og:locale" content="en_US"/>
12
<meta property="og:site_name" content="Steve0Greatness' Site"/>
13
14
<link rel="stylesheet" href="/src/pygments-friendly.css" />
15
<link rel="stylesheet" href="/src/blog.css" />
16
<link rel="alternate" href="/blog/How-to-Store-Passwords.txt" type="text/plain" title="Post source" />
17
<meta property="og:title" content="How to Store a Passwords" />
18
<meta property="og:url" content="https://steve0greatness.github.io/blog/How-to-Store-Passwords.html" />
19
20
</head>
21
22
<body>
23
<header>
24
<h2><a href="/">Steve0Greatness</a></h2>
25
<nav>
26
<a href="/blog">Blog</a>
27
<a href="/link-tree.html">Link Tree</a>
28
</nav>
29
</header>
30
31
<ol role="navigation" class="breadcrumbs" aria-roledescription="Site breadcrumb">
32
<li>
33
<a href="/">Index</a>
34
</li>
35
36
<li >
37
<a href="/blog">
38
Blog Index
39
</a>
40
</li>
41
42
<li aria-current="location">
43
44
How to Store a Passwords
45
46
</li>
47
48
</ol>
49
<main>
50
<article>
51
<header>
52
<h2 id="blog-post-titled">How to Store a Passwords</h2>
53
<div role="toolbar" class="toolbar">
54
<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">
55
<img src="/toot-kytta-dev-icon.svg" width="16" height="16" aria-hidden="true" title="Share to Mastodon" />
56
</a>
57
<a href="/blog/How-to-Store-Passwords.html" title="Direct link">
58
<span aria-hidden="true">
59
&#128279;
60
</span>
61
</a>
62
<a href="/blog/How-to-Store-Passwords.txt" title="Markdown source">
63
<img src="/md-src.svg" width="16" height="16" aria-hidden="true" />
64
</a>
65
</div>
66
<time>2023 Nov 2</time>
67
</header>
68
<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>
69
70
<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>
71
72
<p>Basically, it's just this sequence of steps:</p>
73
74
<ul>
75
<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>
76
<li>Prepend(or append, it doesn't matter, just keep it consistent) this to the user's password</li>
77
<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>
78
<li>Store the salt and hash in the same place, <em>do not</em> store the password on it's own.</li>
79
</ul>
80
81
<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>
82
83
<h2 id="why-do-this">Why Do <em>This</em>?</h2>
84
85
<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>
86
87
<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>
88
89
<h3 id="plaintext-passwords">Plaintext Passwords</h3>
90
91
<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>
92
93
<h3 id="encrypted-passwords">Encrypted Passwords</h3>
94
95
<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>
96
97
<h3 id="bare-hashing">Bare Hashing</h3>
98
99
<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>
100
101
<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>
102
103
</article>
104
</main>
105
<footer role="group">
106
<div class="footer-link-list-holder">
107
<span aria-hidden="true" id="footer-label-site-details" class="footer-link-list-label">Site Meta</span>
108
<ol class="footer-link-list" aria-labelledby="footer-label-site-details">
109
<li><a href="https://github.com/Steve0Greatness/steve0greatness.github.io">Github Repository</a></li>
110
<li><a href="https://steve0greatness.github.io/extras">Extras Archive</a></li>
111
</ol>
112
</div>
113
<div class="footer-link-list-holder">
114
<span aria-hidden="true" id="footer-label-social-accounts" class="footer-link-list-label">Social Accounts</span>
115
<ol class="footer-link-list" aria-labelledby="footer-label-social-accounts">
116
<li><a href="https://mastodon.social/@S0G" rel="me">Mastodon</a></li>
117
<li><a href="https://youtube.com/@s0g">YouTube</a></li>
118
<li><a href="/link-tree.html">More...</a></li>
119
</ol>
120
</div>
121
</footer>
122
</body>
123
124
</html>