Last active
November 23, 2021 15:35
-
-
Save chsh/6633785 to your computer and use it in GitHub Desktop.
Generate apache compatible htpasswd file using Ruby.
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
# generate apache compatible htpasswd file using Ruby. | |
require 'webrick' | |
if ARGV.size < 3 | |
puts "usage: #{$0} password-file user password" | |
exit 1 | |
end | |
# create htpassword instance | |
passwordfile = ARGV.shift | |
passwd = WEBrick::HTTPAuth::Htpasswd.new(passwordfile) | |
# register password | |
user = ARGV.shift | |
password = ARGV.shift | |
passwd.set_passwd(nil, user, password) | |
passwd.flush # save | |
puts IO.read(passwordfile) | |
# get crypted password | |
enc_pass = passwd.get_passwd(nil, user, false) | |
puts enc_pass |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment