Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit458c5dc

Browse files
committed
fixup! fix: user passwords cleanup
1 parent44c04ec commit458c5dc

File tree

3 files changed

+14
-50
lines changed

3 files changed

+14
-50
lines changed

‎coderd/userpassword/hashing_bench_test.go

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ import (
1010
)
1111

1212
var (
13-
salt= []byte(cryptorand.MustString(16))
14-
secret= []byte(cryptorand.MustString(24))
13+
salt= []byte(must(cryptorand.String(16)))
14+
secret= []byte(must(cryptorand.String(24)))
1515

1616
resBcrypt []byte
1717
resPbkdf2 []byte
@@ -60,3 +60,11 @@ func BenchmarkPbkdf2(b *testing.B) {
6060

6161
resPbkdf2=r
6262
}
63+
64+
funcmust(sstring,errerror)string {
65+
iferr!=nil {
66+
panic(err)
67+
}
68+
69+
returns
70+
}

‎coderd/userpassword/userpassword.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,6 @@ import (
1313
"golang.org/x/crypto/pbkdf2"
1414
"golang.org/x/exp/slices"
1515
"golang.org/x/xerrors"
16-
17-
"github.com/coder/coder/cryptorand"
1816
)
1917

2018
var (
@@ -40,7 +38,7 @@ var (
4038

4139
// The simulated hash is used when trying to simulate password checks for
4240
// users that don't exist.
43-
simulatedHash,_=Hash(cryptorand.MustString(10))
41+
simulatedHash,_=Hash("hunter2")
4442
)
4543

4644
// Make password hashing much faster in tests.

‎cryptorand/strings.go

Lines changed: 3 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@ import (
44
"crypto/rand"
55
"encoding/binary"
66
"strings"
7-
8-
"golang.org/x/xerrors"
97
)
108

119
// Charsets
@@ -34,7 +32,7 @@ const (
3432
Human="23456789abcdefghjkmnpqrstuvwxyz"
3533
)
3634

37-
// StringCharset generates a random string using the provided charset and size.
35+
// StringCharset generates a random string using the provided charset and size
3836
funcStringCharset(charSetStrstring,sizeint) (string,error) {
3937
charSet:= []rune(charSetStr)
4038

@@ -69,58 +67,18 @@ func StringCharset(charSetStr string, size int) (string, error) {
6967
returnbuf.String(),nil
7068
}
7169

72-
// MustStringCharset generates a random string of the given length, using the
73-
// provided charset. It will panic if an error occurs.
74-
funcMustStringCharset(charSetstring,sizeint)string {
75-
s,err:=StringCharset(charSet,size)
76-
must(err)
77-
returns
78-
}
79-
8070
// String returns a random string using Default.
8171
funcString(sizeint) (string,error) {
8272
returnStringCharset(Default,size)
8373
}
8474

85-
// MustString generates a random string of the given length, using
86-
// the Default charset. It will panic if an error occurs.
87-
funcMustString(sizeint)string {
88-
s,err:=String(size)
89-
must(err)
90-
returns
91-
}
92-
9375
// HexString returns a hexadecimal string of given length.
9476
funcHexString(sizeint) (string,error) {
9577
returnStringCharset(Hex,size)
9678
}
9779

98-
// MustHexString generates a random hexadecimal string of the given
99-
// length. It will panic if an error occurs.
100-
funcMustHexString(sizeint)string {
101-
s,err:=HexString(size)
102-
must(err)
103-
returns
104-
}
105-
106-
// Sha1String returns a 40-character hexadecimal string, which matches the
107-
// length of a SHA-1 hash (160 bits).
80+
// Sha1String returns a 40-character hexadecimal string, which matches
81+
// the length of a SHA-1 hash (160 bits).
10882
funcSha1String() (string,error) {
10983
returnStringCharset(Hex,40)
11084
}
111-
112-
// MustSha1String returns a 40-character hexadecimal string, which matches the
113-
// length of a SHA-1 hash (160 bits). It will panic if an error occurs.
114-
funcMustSha1String()string {
115-
s,err:=Sha1String()
116-
must(err)
117-
returns
118-
}
119-
120-
// must is a utility function that panics with the given error if
121-
// err is non-nil.
122-
funcmust(errerror) {
123-
iferr!=nil {
124-
panic(xerrors.Errorf("crand: %w",err))
125-
}
126-
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp