Skip to content

Instantly share code, notes, and snippets.

@double-p
Created October 4, 2017 10:19
Show Gist options
  • Save double-p/8c9bd62008a2fd315d9799f04e426e5c to your computer and use it in GitHub Desktop.
Save double-p/8c9bd62008a2fd315d9799f04e426e5c to your computer and use it in GitHub Desktop.
require 'digest/sha2'
begin
require 'io/console'
rescue LoadError
$no_io_console = true
end
def ask_noecho(message)
$stderr.print message
if $no_io_console
begin
`stty -echo`
result = gets
ensure
`stty echo`
end
else
result = $stdin.noecho(&:gets)
end
$stderr.puts
result
end
password = ask_noecho("Enter password: ")
twice = ask_noecho("Verify password: ")
if password != twice
abort "Passwords don't match"
end
password.chomp!
salt = rand(36**8).to_s(36)
shadow_hash = password.crypt("$6$" + salt)
puts shadow_hash
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment