MCPcopy Create free account
hub / github.com/bytebase/bytebase / validatePasswordWithRestriction

Function validatePasswordWithRestriction

backend/api/v1/user_service.go:297–314  ·  view source on GitHub ↗
(password string, passwordRestriction *storepb.WorkspaceProfileSetting_PasswordRestriction)

Source from the content-addressed store, hash-verified

295}
296
297func validatePasswordWithRestriction(password string, passwordRestriction *storepb.WorkspaceProfileSetting_PasswordRestriction) error {
298 if len(password) < int(passwordRestriction.GetMinLength()) {
299 return connect.NewError(connect.CodeInvalidArgument, errors.Errorf("password length should no less than %v characters", passwordRestriction.GetMinLength()))
300 }
301 if passwordRestriction.GetRequireNumber() && !regexp.MustCompile("[0-9]+").MatchString(password) {
302 return connect.NewError(connect.CodeInvalidArgument, errors.Errorf("password must contains at least 1 number"))
303 }
304 if passwordRestriction.GetRequireLetter() && !regexp.MustCompile("[a-zA-Z]+").MatchString(password) {
305 return connect.NewError(connect.CodeInvalidArgument, errors.Errorf("password must contains at least 1 lower case letter"))
306 }
307 if passwordRestriction.GetRequireUppercaseLetter() && !regexp.MustCompile("[A-Z]+").MatchString(password) {
308 return connect.NewError(connect.CodeInvalidArgument, errors.Errorf("password must contains at least 1 upper case letter"))
309 }
310 if passwordRestriction.GetRequireSpecialCharacter() && !regexp.MustCompile(`[!@#$%^&*()_+\-=\[\]{};':"\\|,.<>\/?]+`).MatchString(password) {
311 return connect.NewError(connect.CodeInvalidArgument, errors.Errorf("password must contains at least 1 special character"))
312 }
313 return nil
314}
315
316// UpdateUser updates a user.
317func (s *UserService) UpdateUser(ctx context.Context, request *connect.Request[v1pb.UpdateUserRequest]) (*connect.Response[v1pb.User], error) {

Callers 3

validatePasswordMethod · 0.85
SignupMethod · 0.85
ResetPasswordMethod · 0.85

Calls 6

ErrorfMethod · 0.80
GetMinLengthMethod · 0.45
GetRequireNumberMethod · 0.45
GetRequireLetterMethod · 0.45

Tested by

no test coverage detected