Skip to content

Commit 449947f

Browse files
committed
fixup! fix: user passwords cleanup
1 parent 458c5dc commit 449947f

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

coderd/userpassword/userpassword.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import (
1818
var (
1919
// The base64 encoder used when producing the string representation of
2020
// hashes.
21-
base64Encoder = base64.RawStdEncoding
21+
base64Encoding = base64.RawStdEncoding
2222

2323
// The number of iterations to use when generating the hash. This was chosen
2424
// to make it about as fast as bcrypt hashes. Increasing this causes hashes
@@ -34,7 +34,7 @@ var (
3434

3535
// A salt size of 16 is the default in passlib. A minimum of 8 can be safely
3636
// used.
37-
saltSize = 16
37+
defaultSaltSize = 16
3838

3939
// The simulated hash is used when trying to simulate password checks for
4040
// users that don't exist.
@@ -84,7 +84,7 @@ func Compare(hashed string, password string) (bool, error) {
8484
if err != nil {
8585
return false, xerrors.Errorf("parse iter from hash: %w", err)
8686
}
87-
salt, err := base64Encoder.DecodeString(parts[3])
87+
salt, err := base64Encoding.DecodeString(parts[3])
8888
if err != nil {
8989
return false, xerrors.Errorf("decode salt: %w", err)
9090
}
@@ -99,7 +99,7 @@ func Compare(hashed string, password string) (bool, error) {
9999
// Hash generates a hash using pbkdf2.
100100
// See the Compare() comment for rationale.
101101
func Hash(password string) (string, error) {
102-
salt := make([]byte, saltSize)
102+
salt := make([]byte, defaultSaltSize)
103103
_, err := rand.Read(salt)
104104
if err != nil {
105105
return "", xerrors.Errorf("read random bytes for salt: %w", err)
@@ -112,12 +112,12 @@ func Hash(password string) (string, error) {
112112
func hashWithSaltAndIter(password string, salt []byte, iter int) string {
113113
var (
114114
hash = pbkdf2.Key([]byte(password), salt, iter, hashLength, sha256.New)
115-
encHash = make([]byte, base64Encoder.EncodedLen(len(hash)))
116-
encSalt = make([]byte, base64Encoder.EncodedLen(len(salt)))
115+
encHash = make([]byte, base64Encoding.EncodedLen(len(hash)))
116+
encSalt = make([]byte, base64Encoding.EncodedLen(len(salt)))
117117
)
118118

119-
base64Encoder.Encode(encHash, hash)
120-
base64Encoder.Encode(encSalt, salt)
119+
base64Encoding.Encode(encHash, hash)
120+
base64Encoding.Encode(encSalt, salt)
121121

122122
return fmt.Sprintf("$%s$%d$%s$%s", hashScheme, iter, encSalt, encHash)
123123
}

0 commit comments

Comments
 (0)