Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions server/channels/app/password/hashers/pbkdf2.go
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,10 @@ func (p PBKDF2) Hash(password string) (string, error) {
// The provided [phcparser.PHC] is validated to double-check it was generated with
// this hasher and parameters.
func (p PBKDF2) CompareHashAndPassword(hash phcparser.PHC, password string) error {
if len(password) > PasswordMaxLengthBytes {
return ErrPasswordTooLong
}

// Validate parameters
if !p.IsPHCValid(hash) {
return fmt.Errorf("the stored password does not comply with the PBKDF2 parser's PHC serialization")
Expand Down
10 changes: 10 additions & 0 deletions server/channels/app/password/hashers/pbkdf2_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"crypto/pbkdf2"
"crypto/sha256"
"encoding/base64"
"math/rand"
"strings"
"testing"

Expand Down Expand Up @@ -46,6 +47,9 @@ func TestPBKDF2Hash(t *testing.T) {
}

func TestPBKDF2CompareHashAndPassword(t *testing.T) {
passwordTooLong := make([]byte, PasswordMaxLengthBytes+1)
rand.Read(passwordTooLong)

testCases := []struct {
testName string
storedPwd string
Expand All @@ -71,6 +75,12 @@ func TestPBKDF2CompareHashAndPassword(t *testing.T) {
"another password",
ErrMismatchedHashAndPassword,
},
{
"password too long",
"stored password",
string(passwordTooLong),
ErrPasswordTooLong,
},
}

hasher := DefaultPBKDF2()
Expand Down
Loading