Why AI tools produce this: AI coding tools generate this anti-pattern by default, it appears in a large share of AI-written auth code.
Why this matters
These algorithms are designed to be fast, which makes offline brute-force and rainbow-table attacks cheap. They are NOT suitable for storing passwords (CWE-916).
Use a dedicated, slow password-hashing function with a per-password salt and a tunable work factor: bcrypt (golang.org/x/crypto/bcrypt.GenerateFromPassword), Argon2 (golang.org/x/crypto/argon2.IDKey), or scrypt (golang.org/x/crypto/scrypt.Key). These resist brute-force by design.
package mainimport ( "crypto/sha256" "fmt" "golang.org/x/crypto/bcrypt")// Secure: passwords are hashed with bcrypt, a slow, salted password hasher.func hashPassword(password string) ([]byte, error) { // ok: auth.go.crypto.weak-password-hash return bcrypt.GenerateFromPassword([]byte(password), bcrypt.DefaultCost)}// Non-password use of a fast digest: checksumming file contents. Not flagged.func checksum(fileBytes []byte) [32]byte { // ok: auth.go.crypto.weak-password-hash return sha256.Sum256(fileBytes)}func main() { hash, _ := hashPassword("hunter2") fmt.Println(hash, checksum([]byte("file contents")))}
Suppressing this rule
If a finding is a genuine false positive, scope the suppression to the exact line and leave a reason, never disable the rule project-wide. Disable directives are line-scoped by design.