summary refs log tree commit diff stats
path: root/auth
diff options
context:
space:
mode:
authorAndinus <andinus@nand.sh>2020-03-29 16:10:59 +0530
committerAndinus <andinus@nand.sh>2020-03-29 16:10:59 +0530
commita6826055bf4e6a23f80da047ccfe4509a209f3a6 (patch)
treef2bb2bec35ee5e61cb42f4edffb04368a0f8ba60 /auth
parent7b95d6b80dd2d1efb26f7c515383abd4f0dc9d42 (diff)
downloadperseus-a6826055bf4e6a23f80da047ccfe4509a209f3a6.tar.gz
Initial perseus rewrite
Diffstat (limited to 'auth')
-rw-r--r--auth/checkpass.go14
-rw-r--r--auth/checkpass_test.go40
-rw-r--r--auth/genid.go14
-rw-r--r--auth/hashpass.go13
-rw-r--r--auth/hashpass_test.go34
5 files changed, 0 insertions, 115 deletions
diff --git a/auth/checkpass.go b/auth/checkpass.go
deleted file mode 100644
index 64e3c9f..0000000
--- a/auth/checkpass.go
+++ /dev/null
@@ -1,14 +0,0 @@
-package auth
-
-import (
-	"golang.org/x/crypto/bcrypt"
-)
-
-// checkPass takes a string and hash as input and returns an error. If
-// the error is not nil then the consider the password wrong. We're
-// returning error instead of a bool so that we can print failed
-// logins to log and logging shouldn't happen here.
-func checkPass(password, hash string) error {
-	err := bcrypt.CompareHashAndPassword([]byte(hash), []byte(password))
-	return err
-}
diff --git a/auth/checkpass_test.go b/auth/checkpass_test.go
deleted file mode 100644
index c8afaee..0000000
--- a/auth/checkpass_test.go
+++ /dev/null
@@ -1,40 +0,0 @@
-package auth
-
-import "testing"
-
-// TestCheckPass tests the checkPass function.
-func TestCheckPass(t *testing.T) {
-	var err error
-	passhash := make(map[string]string)
-
-	// First we check with static values, these should always pass.
-	passhash["ter4cQ=="] = "$2a$10$ANkaNEFFQ4zxDwTwvAUfoOCqpVIdgtPFopFOTMSrFy39WkaMAYLIC"
-	passhash["G29J6A=="] = "$2a$10$1oH1PyhncIHcHJWbLt3Gv.OjClUoFoaEDaFpQ9E9atfRbIrVxsbwm"
-	passhash["Z1S/kQ=="] = "$2a$10$fZ05kKmb7bh4vBLebpK1u.3bUNQ6eeX5ghT/GZaekgS.5bx4.Ru1e"
-	passhash["J861dQ=="] = "$2a$10$nXb6Btn6n3AWMAUkDh9bFObvQw5V9FLKhfX.E1EzRWgVDuqIp99u2"
-
-	// We also check with values generated with hashPass, this may
-	// fail if hashPass itself fails in that case it's not
-	// checkPass error so the test shouldn't fail but warning
-	// should be sent. We use genID func to generate random inputs
-	// for this test.
-	for i := 1; i <= 4; i++ {
-		p := genID(8)
-		passhash[p], err = hashPass(p)
-		if err != nil {
-			t.Log("hashPass func failed")
-		}
-	}
-
-	// We test the checkPass func by ranging over all values of
-	// passhash. We assume that hashPass func returns correct
-	// hashes.
-	for p, h := range passhash {
-		err = checkPass(p, h)
-		if err != nil {
-			t.Errorf("password: %s, hash: %s didn't match.",
-				p, h)
-		}
-	}
-
-}
diff --git a/auth/genid.go b/auth/genid.go
deleted file mode 100644
index fea7ac9..0000000
--- a/auth/genid.go
+++ /dev/null
@@ -1,14 +0,0 @@
-package auth
-
-import (
-	"crypto/rand"
-	"encoding/base64"
-)
-
-// genID generates a random id string of length n. Don't forget to
-// seed the random number generator otherwise it won't be random.
-func genID(n int) string {
-	b := make([]byte, n/2)
-	rand.Read(b)
-	return base64.StdEncoding.EncodeToString(b)
-}
diff --git a/auth/hashpass.go b/auth/hashpass.go
deleted file mode 100644
index 4e5041a..0000000
--- a/auth/hashpass.go
+++ /dev/null
@@ -1,13 +0,0 @@
-package auth
-
-import (
-	"golang.org/x/crypto/bcrypt"
-)
-
-// hashPass takes a string as input and returns the hash of the
-// password.
-func hashPass(password string) (string, error) {
-	// 10 is the default cost.
-	bytes, err := bcrypt.GenerateFromPassword([]byte(password), 10)
-	return string(bytes), err
-}
diff --git a/auth/hashpass_test.go b/auth/hashpass_test.go
deleted file mode 100644
index 7ea9480..0000000
--- a/auth/hashpass_test.go
+++ /dev/null
@@ -1,34 +0,0 @@
-package auth
-
-import "testing"
-
-// TestHashPass tests the checkPass function.
-func TestHashPass(t *testing.T) {
-	var err error
-	passhash := make(map[string]string)
-
-	// We generate random hashes with hashPass, random string is
-	// generate by genID func.
-	for i := 1; i <= 8; i++ {
-		p := genID(8)
-		passhash[p], err = hashPass(p)
-
-		// Here we test if the hashPass func runs sucessfully.
-		if err != nil {
-			t.Errorf("hashPass func failed for password: %s",
-				p)
-		}
-	}
-
-	// Here we are testing if the hashPass func returns correct
-	// hashes. We assume that checkPass func returns correct
-	// values.
-	for p, h := range passhash {
-		err = checkPass(p, h)
-		if err != nil {
-			t.Errorf("password: %s, hash: %s didn't match.",
-				p, h)
-		}
-	}
-
-}
tik.com> 2020-07-06 01:05:10 -0700 6618 - new docs' href='/akkartik/mu/commit/vocabulary.md?h=hlt&id=9a524793ee01ce47f3963768559a0d6c348631c5'>9a524793 ^
cec5ef31 ^
9a524793 ^
cec5ef31 ^

9a524793 ^
cec5ef31 ^

9a524793 ^
cec5ef31 ^



9a524793 ^
cec5ef31 ^


9a524793 ^
cec5ef31 ^

9a524793 ^
cec5ef31 ^
9a524793 ^
cec5ef31 ^




9a524793 ^
cec5ef31 ^
9a524793 ^
cec5ef31 ^







9a524793 ^
02b7f9bd ^
9a524793 ^


cec5ef31 ^

4b57c101 ^

cec5ef31 ^





e6b42204 ^

cec5ef31 ^
9a524793 ^
cec5ef31 ^
















b9883225 ^



cec5ef31 ^























































































b9883225 ^



















1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249