{"record":{"id":"ff5dd0c3ea41a709","repo":"Billionmail/BillionMail","slug":"generate-password-md5-crypt-failed-w","errorCode":null,"errorMessage":"Generate password md5-crypt failed: %w","messagePattern":"Generate password md5-crypt failed: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"core/internal/service/mail_boxes/mail_boxes.go","lineNumber":32,"sourceCode":"\t\"github.com/gogf/gf/v2/frame/g\"\n\t\"github.com/gogf/gf/v2/util/gconv\"\n\t\"math/rand\"\n\t\"os\"\n\t\"path/filepath\"\n\t\"regexp\"\n\t\"strings\"\n\t\"time\"\n)\n\nfunc Add(ctx context.Context, mailbox *v1.Mailbox) (err error) {\n\t// Encode password\n\tmailbox.PasswordEncode = PasswdEncode(ctx, mailbox.Password)\n\n\t// Crypt password\n\tmailbox.Password, err = PasswdMD5Crypt(ctx, mailbox.Password)\n\n\tif err != nil {\n\t\terr = fmt.Errorf(\"Generate password md5-crypt failed: %w\", err)\n\t\treturn\n\t}\n\n\tmailbox.Username = strings.ToLower(mailbox.Username)\n\tmailbox.LocalPart = strings.ToLower(mailbox.LocalPart)\n\tmailbox.Domain = strings.ToLower(mailbox.Domain)\n\n\tnow := time.Now().Unix()\n\tmailbox.CreateTime = now\n\tmailbox.UpdateTime = now\n\tmailbox.Active = 1\n\tmailbox.Maildir = fmt.Sprintf(\"%s@%s/\", mailbox.LocalPart, mailbox.Domain)\n\n\t_, err = g.DB().Model(\"mailbox\").Ctx(ctx).Insert(mailbox)\n\tif err != nil {\n\t\tif strings.Contains(err.Error(), \"duplicate\") || strings.Contains(err.Error(), \"unique\") {\n\t\t\treturn fmt.Errorf(\"mailbox %s already exists\", mailbox.Username)\n\t\t}","sourceCodeStart":14,"sourceCodeEnd":50,"githubUrl":"https://github.com/Billionmail/BillionMail/blob/fc36c76c050c3775c5e899faf7403cf0262d2744/core/internal/service/mail_boxes/mail_boxes.go#L14-L50","documentation":"Add (mailbox creation) hashes the plaintext password with md5-crypt via PasswdMD5Crypt for Dovecot compatibility. If the crypt operation fails, the error is wrapped as 'Generate password md5-crypt failed'.","triggerScenarios":"PasswdMD5Crypt(ctx, mailbox.Password) returns an error — typically an empty/oversized password, or a failure in the underlying crypt library (unsupported algorithm, salt generation failure, crypto/rand unavailable).","commonSituations":"API caller submits a mailbox with an empty password field; password containing characters truncated by an upstream validator; environment where /dev/urandom is unavailable; upgrading a crypt dependency with changed behavior.","solutions":["Validate the password is non-empty and within length limits before calling Add","Inspect the wrapped %w error for the underlying crypt failure","Regenerate with a supported md5-crypt implementation / update the crypt library","Confirm crypto/rand entropy sources are available in the container"],"exampleFix":"// before\nmailbox.Password, err = PasswdMD5Crypt(ctx, mailbox.Password)\n// after\nif mailbox.Password == \"\" {\n\treturn fmt.Errorf(\"mailbox password must not be empty\")\n}\nmailbox.Password, err = PasswdMD5Crypt(ctx, mailbox.Password)\nif err != nil {\n\terr = fmt.Errorf(\"Generate password md5-crypt failed: %w\", err)\n\treturn\n}","handlingStrategy":"validation","validationCode":"func validPassword(pw string) bool {\n\treturn len(pw) >= 8 && len(pw) <= 128\n}\nif !validPassword(mailbox.Password) {\n\treturn fmt.Errorf(\"password length must be 8-128 characters\")\n}","typeGuard":null,"tryCatchPattern":"err := mail_boxes.Add(ctx, mailbox)\nif err != nil && strings.Contains(err.Error(), \"Generate password md5-crypt failed\") {\n\tlog.Printf(\"reject input: %v\", errors.Unwrap(err))\n}","preventionTips":["Validate password non-empty and within length limits at the API layer","Pin and test the crypt library version","Verify entropy sources (/dev/urandom) are available in containers","Return the unwrapped cause in logs for diagnosis"],"tags":["crypto","password","mailbox","validation"],"backgroundTag":"password-hash-failed","analyzedSha":"fc36c76c050c3775c5e899faf7403cf0262d2744","analyzedAt":"2026-09-05T21:28:54.019Z","contentChangedAt":"2026-09-05T21:28:54.019Z","schemaVersion":2},"datasetVersion":"2026-09-12T22:17:10.623Z"}