Created
October 4, 2017 10:19
-
-
Save double-p/8c9bd62008a2fd315d9799f04e426e5c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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