Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: additional constant time code #24887

Merged
merged 1 commit into from
Apr 5, 2024
Merged
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
9 changes: 9 additions & 0 deletions tenant/service_user.go
Original file line number Diff line number Diff line change
Expand Up @@ -293,14 +293,18 @@ var classes []func(rune) bool = []func(rune) bool{
func IsPasswordStrong(password string, doCheck bool) error {
const numClassesRequired = 3
var eSlice []error = nil
var tslice []error = nil
l := len(password)
if l < errors.MinPasswordLen || l > errors.MaxPasswordLen {
eSlice = append(eSlice, errors.EPasswordLength)
} else {
tslice = append(tslice, errors.EPasswordLength)
}
if doCheck {
// make a password copy that is the length of the max password length
constLenPassword := strings.Repeat(password, 1+(errors.MaxPasswordLen/len(password)))[:errors.MaxPasswordLen]
n := 0
t := 0

// Walk the whole string for each class, for constant time operation
for _, f := range classes {
Expand All @@ -310,12 +314,17 @@ func IsPasswordStrong(password string, doCheck bool) error {
}
if found {
n++
} else {
t++
}
}
if n < numClassesRequired {
eSlice = append(eSlice, errors.EPasswordChars)
} else {
tslice = append(tslice, errors.EPasswordChars)
}
}
eBase.Join(tslice...)
return eBase.Join(eSlice...)
}

Expand Down