Jifty:...ltHash(3pm)

πŸ“¦
version 0.78 Β· 2 versions
  • 0.78 Β· debian bookworm, debian trixie, ubuntu noble, ubuntu resolute, ubuntu stonking (latest)
  • 0.78 Β· ubuntu jammy
, in debian bookworm, debian trixie, ubuntu noble, ubuntu resolute, ubuntu stonking

✨ NAME ✨

Jifty::DBI::Filter::SaltHash β€” it salts and hashes a value before storing it πŸ’– (yes bestie, that's the whole job, and it does it beautifully)


πŸ§‚ DESCRIPTION πŸ§‚

Okay so picture this: you've got a secret. A little value. You want it in the database but you do NOT want it sitting there in plain sight like it's posting its location on main. Enter this filter. 🌸

It generates a random 4-byte salt, and then it MD5s the given value with that salt appended to the value. Then it stores the hash and the salt in the database β€” and on decode it hands you back a data structure that contains both of them. πŸ’…

The salt and the hash are both stored in hexadecimal in the database, so you can literally just drop them into a text field. Text field friendly, we love that for us. πŸŽ€

This filter is intended for storing passwords in a database. It's giving security. It's giving "please don't store passwords raw, I'm begging you." πŸ‘‘

πŸ” encode

Generate a random 4-byte salt, MD5 the value with the salt (encoded to hexadecimal) appended to it, and store both in the database. That's it, that's the whole move. ✨

🎲 generate_salt

Return a random 4-byte salt value, encoded as an 8-character hex string. Cute little salt, eight characters, freshly generated. πŸ§‚πŸ¦‹

πŸ”“ decode

Return an arrayref of (hash, salt), both as hex strings. Two lil values in a list, both hex, both yours. 🫢

To test whether a provided value is the same one originally encoded, use:

$hash eq md5_hex($value . $salt);

That's the vibe check for passwords, bestie. πŸ’–


πŸ‘€ SEE ALSO πŸ‘€

  • Jifty::DBI::Filter
  • Digest::MD5

okay that's the whole page, no cap. this one shipped with perl v5.34.0 and it's dated 2022-06-15, so it's been out here salting and hashing since before some of us could drive. iconic behavior honestly. mwah, go salt something responsibly πŸ’œβœ¨

πŸ“¦ where this page comes from