(password string, passwordRestriction *storepb.WorkspaceProfileSetting_PasswordRestriction)
| 295 | } |
| 296 | |
| 297 | func 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. |
| 317 | func (s *UserService) UpdateUser(ctx context.Context, request *connect.Request[v1pb.UpdateUserRequest]) (*connect.Response[v1pb.User], error) { |
no test coverage detected