apache/answer · error

error.password.space_invalid

error.password.space_invalid

Error message

error.password.space_invalid

What it means

CheckPassword enforces password rules; currently the only enforced rule is that the password must not contain a space character. Violating it returns the translatable code error.password.space_invalid.

Source

Thrown at pkg/checker/password.go:44

	"strings"
)

const (
	levelD = iota
	LevelC
	LevelB
	LevelA
	LevelS
)

const (
	PasswordCannotContainSpaces = "error.password.space_invalid"
)

// CheckPassword checks the password strength
func CheckPassword(password string) error {
	if strings.Contains(password, " ") {
		return errors.New(PasswordCannotContainSpaces)
	}

	// TODO Currently there is no requirement for password strength
	minLevel := 0

	// The password strength level is initialized to D.
	// The regular is used to verify the password strength.
	// If the matching is successful, the password strength increases by 1
	level := levelD
	patternList := []string{`[0-9]+`, `[a-z]+`, `[A-Z]+`, `[~!@#$%^&*?_-]+`}
	for _, pattern := range patternList {
		match, _ := regexp.MatchString(pattern, password)
		if match {
			level++
		}
	}

	// If the final password strength falls below the required minimum strength, return with an error

View on GitHub (pinned to 3b9f137061)

Solutions

  1. Remove space characters from the password and retry.
  2. Sanitize/validate the password client-side before submission to give early feedback.
  3. Improve UX: show the 'password cannot contain spaces' rule in the form hint.
  4. If passphrase-style passwords are desired, update CheckPassword to allow spaces and adjust the i18n message.

Example fix

// before
const password = 'my secret 123';
await resetPassword(password);
// after
const password = 'my-secret-123';
await resetPassword(password);
Defensive patterns

Strategy: validation

Validate before calling

function passwordHasSpace(pw: string): boolean { return /\s/.test(pw); }
if (passwordHasSpace(pw)) alert('Password cannot contain spaces');

Try / catch

try {
  await api.resetPassword(pw);
} catch (e) {
  if (e?.msg === 'error.password.space_invalid') {
    showError(t('error.password.space_invalid'));
  }
}

Prevention

When it happens

Trigger: Calling CheckPassword (directly or via ResetPassword/Check flows) with a password containing a space, e.g. 'my pass123'.

Common situations: Users typing passphrases with spaces in the reset-password or change-password form; promptForPassword in CLI setup accepting any input including spaces; password managers generating passphrases with spaces.

Related errors


AI-assisted analysis of apache/answer@3b9f137061 (2026-09-05). Data as JSON: /api/errors/276b7142fae31a7f. Report an issue: GitHub.