Skip to content

Commit

Permalink
sysvar: fix inconsistency in setting password validation sysvars (#39584
Browse files Browse the repository at this point in the history
)

ref #38928
  • Loading branch information
CbcWestwolf authored Dec 3, 2022
1 parent e89f341 commit 0b1096e
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
15 changes: 12 additions & 3 deletions sessionctx/variable/sysvar.go
Original file line number Diff line number Diff line change
Expand Up @@ -520,7 +520,10 @@ var defaultSysVars = []*SysVar{
return "", err
}
if minLength := numberCount + specialCharCount + 2*int32(mixedCaseCount); length < minLength {
PasswordValidationLength.Store(minLength)
err = updatePasswordValidationLength(vars, minLength)
if err != nil {
return "", err
}
}
return normalizedValue, nil
},
Expand All @@ -539,7 +542,10 @@ var defaultSysVars = []*SysVar{
return "", err
}
if minLength := int32(numberCount) + specialCharCount + 2*mixedCaseCount; length < minLength {
PasswordValidationLength.Store(minLength)
err = updatePasswordValidationLength(vars, minLength)
if err != nil {
return "", err
}
}
return normalizedValue, nil
},
Expand All @@ -558,7 +564,10 @@ var defaultSysVars = []*SysVar{
return "", err
}
if minLength := numberCount + int32(specialCharCount) + 2*mixedCaseCount; length < minLength {
PasswordValidationLength.Store(minLength)
err = updatePasswordValidationLength(vars, minLength)
if err != nil {
return "", err
}
}
return normalizedValue, nil
},
Expand Down
10 changes: 10 additions & 0 deletions sessionctx/variable/varsutil.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
package variable

import (
"context"
"fmt"
"io"
"strconv"
Expand Down Expand Up @@ -531,6 +532,15 @@ func collectAllowFuncName4ExpressionIndex() string {
return strings.Join(str, ", ")
}

func updatePasswordValidationLength(s *SessionVars, length int32) error {
err := s.GlobalVarsAccessor.SetGlobalSysVarOnly(context.Background(), ValidatePasswordLength, strconv.FormatInt(int64(length), 10))
if err != nil {
return err
}
PasswordValidationLength.Store(length)
return nil
}

// GAFunction4ExpressionIndex stores functions GA for expression index.
var GAFunction4ExpressionIndex = map[string]struct{}{
ast.Lower: {},
Expand Down

0 comments on commit 0b1096e

Please sign in to comment.