{"record":{"id":"276b7142fae31a7f","repo":"apache/answer","slug":"error-password-space-invalid","errorCode":"error.password.space_invalid","errorMessage":"error.password.space_invalid","messagePattern":"error\\.password\\.space_invalid","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/checker/password.go","lineNumber":44,"sourceCode":"\t\"strings\"\n)\n\nconst (\n\tlevelD = iota\n\tLevelC\n\tLevelB\n\tLevelA\n\tLevelS\n)\n\nconst (\n\tPasswordCannotContainSpaces = \"error.password.space_invalid\"\n)\n\n// CheckPassword checks the password strength\nfunc CheckPassword(password string) error {\n\tif strings.Contains(password, \" \") {\n\t\treturn errors.New(PasswordCannotContainSpaces)\n\t}\n\n\t// TODO Currently there is no requirement for password strength\n\tminLevel := 0\n\n\t// The password strength level is initialized to D.\n\t// The regular is used to verify the password strength.\n\t// If the matching is successful, the password strength increases by 1\n\tlevel := levelD\n\tpatternList := []string{`[0-9]+`, `[a-z]+`, `[A-Z]+`, `[~!@#$%^&*?_-]+`}\n\tfor _, pattern := range patternList {\n\t\tmatch, _ := regexp.MatchString(pattern, password)\n\t\tif match {\n\t\t\tlevel++\n\t\t}\n\t}\n\n\t// If the final password strength falls below the required minimum strength, return with an error","sourceCodeStart":26,"sourceCodeEnd":62,"githubUrl":"https://github.com/apache/answer/blob/3b9f1370612e690a0b7f230f05e688930db4c6d3/pkg/checker/password.go#L26-L62","documentation":"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.","triggerScenarios":"Calling CheckPassword (directly or via ResetPassword/Check flows) with a password containing a space, e.g. 'my pass123'.","commonSituations":"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.","solutions":["Remove space characters from the password and retry.","Sanitize/validate the password client-side before submission to give early feedback.","Improve UX: show the 'password cannot contain spaces' rule in the form hint.","If passphrase-style passwords are desired, update CheckPassword to allow spaces and adjust the i18n message."],"exampleFix":"// before\nconst password = 'my secret 123';\nawait resetPassword(password);\n// after\nconst password = 'my-secret-123';\nawait resetPassword(password);","handlingStrategy":"validation","validationCode":"function passwordHasSpace(pw: string): boolean { return /\\s/.test(pw); }\nif (passwordHasSpace(pw)) alert('Password cannot contain spaces');","typeGuard":null,"tryCatchPattern":"try {\n  await api.resetPassword(pw);\n} catch (e) {\n  if (e?.msg === 'error.password.space_invalid') {\n    showError(t('error.password.space_invalid'));\n  }\n}","preventionTips":["Regex-check for whitespace client-side before submit","Display password rules inline in the form","Strip accidental leading/trailing whitespace (but not internal) per policy","Document the rule wherever passwords are set (CLI prompt included)"],"tags":["password","validation","i18n","go"],"backgroundTag":"password-validation-failed","analyzedSha":"3b9f1370612e690a0b7f230f05e688930db4c6d3","analyzedAt":"2026-09-05T18:18:39.533Z","contentChangedAt":"2026-09-05T18:18:39.533Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}