Welcome! Log In Create A New Profile

Advanced

generate an htpasswd file without having Apache tools installed

Posted by atipico 
generate an htpasswd file without having Apache tools installed
June 26, 2011 05:33AM
I'd like to suggest two easy ways to generate an htpasswd file without having Apache tools installed.

Perl
perl -le 'print crypt("password", "salt")'

So, in bash, we could make something like this:
perl -le 'print crypt("password", "salt")' > /etc/nginx/htpasswd

Ruby (run in irb)
"password".crypt("salt")

If the suggestion is accepted, then the topic in the FAQ page <http://wiki.nginx.org/NginxFaq#How_do_I_generate_an_htpasswd_file_without_having_Apache_tools_installed.3F> could be updated.

Grabbed from: http://snippets.aktagon.com/snippets/109-Password-protecting-a-folder-resource-with-Nginx

Thank you,
Rogério Madureira
Re: generate an htpasswd file without having Apache tools installed
June 26, 2011 07:08AM
It seams I gave an incomplete tip in my last message. Sorry.

Here's how to make it in Bash:
echo -e "your-username:`perl -le 'print crypt("your-password","salt")'`" > /etc/nginx/htpasswd

There's also an online tool: http://www.htaccesstools.com/htpasswd-generator/
Re: generate an htpasswd file without having Apache tools installed
September 27, 2011 06:42AM
I agree that this should also be suggested as an alternative to the python example. Its certainly more succinct.
Re: generate an htpasswd file without having Apache tools installed
July 21, 2012 04:15PM
minor update for 2012 ;)
ruby -le 'print "your-username: #{%Q{your password}.crypt(%Q{salt})}"'
Re: generate an htpasswd file without having Apache tools installed
November 03, 2015 01:50AM
Hi.

Just in case someone will step on it too.

'perl -le 'print crypt("password", "salt")' is a root cause for situation when you can input any random sequence after entering valid password. Like, imagine, you have a password "mys3cr3t", and you generated a hash using perl one-liner above. This way, any password of the following ones (and similar in general) will be valid:

mys3cr3t
mys3cr3t11
mys3cr3tkwdhekcgejhcdg
mys3cr3t8776e3df3uyd386dt7d6t

So - use apr1, this is more secure.
Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 300
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready