Generating htpasswd entry in R

November 26, 2019 @Hong Hong Ooi

@Hong wrote:

Is there a way to generate a htpasswd entry using R, ie, without using the htpasswd utility itself?

According to the Apache docs,

htpasswd encrypts passwords using either bcrypt, a version of MD5 modified for Apache, SHA1, or the system's crypt() routine. Files managed by htpasswd may contain a mixture of different encoding types of passwords; some user records may have bcrypt or MD5-encrypted passwords while others in the same file may have passwords encrypted with crypt().

I tried using either openssl::md5 or digest::digest, but they don't seem to be producing anything I can recognise.

Here's some sample output using htpasswd on Ubuntu. The result changes each time, presumably because there is a salt being used. The hash doesn't look like it's base64-encoded either.

hongo@hongsdev:~$ echo bar | htpasswd -n -i foo
foo:$apr1$ArTUhiJz$/qjciBNKHEWwpXBof75rb.

hongo@hongsdev:~$ echo bar | htpasswd -n -i foo
foo:$apr1$pZxmtIam$VkfMvV2qR4NBkPm3MKcJ/.

hongo@hongsdev:~$ echo bar | htpasswd -n -i foo
foo:$apr1$IFM43G9p$UkQB9QSONrwD74WpXlP7f/

Some attempts using openssl::md5 and digest::digest:

r$> openssl::md5("bar")
[1] "37b51d194a7513e45b56f6524f2d51f2"

r$> digest::digest("bar", algo="md5")
[1] "cbd2100992f98ebf9169448cf98f63a5"

r$> openssl::base64_encode(openssl::md5("bar"))
[1] "MzdiNTFkMTk0YTc1MTNlNDViNTZmNjUyNGYyZDUxZjI="

Posts: 5

Participants: 3

Read full topic

Previous Article
About R studio for windows 7
About R studio for windows 7

@TEDDYY wrote: hi, i have installed R 3.6 and R studio but i cant install any pa...

Next Article
Can I use javascript or the RStudio Connect API to get the URL of the current page in Rmarkdown
Can I use javascript or the RStudio Connect API to get the URL of the current page in Rmarkdown

@FvD wrote: In brief: We are trying to do the following, with the aim to include...