{"record":{"id":"e68fc5a4b46ac56b","repo":"apache/answer","slug":"password-length-must-be-at-least-d","errorCode":null,"errorMessage":"password length must be at least %d","messagePattern":"password length must be at least (.+?)","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/cli/reset_password.go","lineNumber":229,"sourceCode":"\tif err != nil {\n\t\treturn \"\", err\n\t}\n\treturn \"\", fmt.Errorf(\"failed to generate valid password after %d retries\", maxRetries)\n}\n\nfunc getPasswordInput(prompt string) (string, error) {\n\tfmt.Print(prompt)\n\tpassword, err := term.ReadPassword(int(os.Stdin.Fd()))\n\tif err != nil {\n\t\treturn \"\", err\n\t}\n\tfmt.Println()\n\treturn string(password), nil\n}\n\nfunc generateRandomPassword(length int) (string, error) {\n\tif length < len(charset) {\n\t\treturn \"\", fmt.Errorf(\"password length must be at least %d\", len(charset))\n\t}\n\n\tbytes := make([]byte, length)\n\tfor i, charsetItem := range charset {\n\t\tcharIndex, err := rand.Int(rand.Reader, big.NewInt(int64(len(charsetItem))))\n\t\tif err != nil {\n\t\t\treturn \"\", err\n\t\t}\n\t\tbytes[i] = charsetItem[charIndex.Int64()]\n\t}\n\n\tfullCharset := strings.Join(charset, \"\")\n\tfor i := len(charset); i < length; i++ {\n\t\tcharIndex, err := rand.Int(rand.Reader, big.NewInt(int64(len(fullCharset))))\n\t\tif err != nil {\n\t\t\treturn \"\", err\n\t\t}\n\t\tbytes[i] = fullCharset[charIndex.Int64()]","sourceCodeStart":211,"sourceCodeEnd":247,"githubUrl":"https://github.com/apache/answer/blob/3b9f1370612e690a0b7f230f05e688930db4c6d3/internal/cli/reset_password.go#L211-L247","documentation":"Validation guard in generateRandomPassword: rejects the requested length because it is smaller than len(charset)=4, the number of character classes that must each appear once to guarantee policy compliance. The at-fault input is the length argument; with the internal default of 12 this can only fire if the constant is changed or the function is called with a smaller length.","triggerScenarios":"Thrown at internal/cli/reset_password.go:229 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Call generateRandomPassword with a length at least equal to len(charset) (one per charset character)","Update the defaultRandomPasswordLength constant to satisfy the charset-coverage requirement","Simplify or shrink the charset if a shorter generated password is required by policy"],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"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"}