{"record":{"id":"1d840eb5c9f51a28","repo":"apache/answer","slug":"encrypt-password-failed-w","errorCode":null,"errorMessage":"encrypt password failed: %w","messagePattern":"encrypt password failed: %w","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/cli/reset_password.go","lineNumber":144,"sourceCode":"\t\tprintWarning(\"Passing password via command line may be recorded in shell history\")\n\t\tif err := checker.CheckPassword(password); err != nil {\n\t\t\treturn fmt.Errorf(\"password validation failed: %w\", err)\n\t\t}\n\t} else {\n\t\tpassword, err = promptForPassword()\n\t\tif err != nil {\n\t\t\treturn fmt.Errorf(\"password input failed: %w\", err)\n\t\t}\n\t}\n\n\tif !confirmAction(fmt.Sprintf(\"This will reset password for user '[%s]%s'. Continue?\", userInfo.DisplayName, email)) {\n\t\tfmt.Println(\"Operation cancelled\")\n\t\treturn nil\n\t}\n\n\thashPwd, err := bcrypt.GenerateFromPassword([]byte(password), bcrypt.DefaultCost)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"encrypt password failed: %w\", err)\n\t}\n\n\tif err = userRepo.UpdatePass(ctx, userInfo.ID, string(hashPwd)); err != nil {\n\t\treturn fmt.Errorf(\"update password failed: %w\", err)\n\t}\n\n\tauthSvc.RemoveUserAllTokens(ctx, userInfo.ID)\n\n\tfmt.Printf(\"Password has been successfully updated for user: %s\\n\", email)\n\tfmt.Println(\"All login sessions have been cleared\")\n\n\treturn nil\n}\n\n// promptForPassword prompts for a password\nfunc promptForPassword() (string, error) {\n\tfor {\n\t\tinput, err := getPasswordInput(\"Please input new password (empty to generate random password): \")","sourceCodeStart":126,"sourceCodeEnd":162,"githubUrl":"https://github.com/apache/answer/blob/3b9f1370612e690a0b7f230f05e688930db4c6d3/internal/cli/reset_password.go#L126-L162","documentation":"Fires in ResetPassword when bcrypt.GenerateFromPassword fails to hash the new password. With bcrypt and DefaultCost this practically only happens when the password exceeds bcrypt's 72-byte input limit, or on internal hash-cost errors; it is a guard around the crypto operation, at fault is the overly long password string.","triggerScenarios":"Thrown at internal/cli/reset_password.go:144 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Retry the operation; bcrypt.GenerateFromPassword rarely fails and a transient failure may not recur","Check available system memory and CPU; bcrypt allocation can fail under resource exhaustion","Verify the password string is valid UTF-8 and of reasonable length before hashing","Upgrade the bcrypt library if the failure persists with DefaultCost"],"exampleFix":null,"handlingStrategy":"retry","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-12T22:17:10.623Z"}