Creating Crypt Style SHA512 Passwords With Ruby
I needed to generate crypt-style SHA512 passwords in ruby for an /etc/shadow
file. After a bunch of Googling and messing around with the OpenSSL library I
finally found a very simple built-in way to handle this.
You'll get a string that looks like:
$6$4dksjo1b$Lt194Dwy7r/7WbM8MezYZysmGcxjaiisgTrTBbHkyBZFXeqQTG0J5hep4wLM/AmYxlGNLRy0OWATLDZCqjwCk.
If you don't want to use the SecureRandom
module you can replace the random
call with simply rand(36 ** 8)
though this isn't recommended.
Enjoy!
development linux ruby security
bd9e1ab3 @ 2024-07-14