htpasswd icon indicating copy to clipboard operation
htpasswd copied to clipboard

BUG: -i only work when storing plain-text password

Open 1000i100 opened this issue 3 years ago • 1 comments

$ npx htpasswd -bBc htpasswd prototype 7ba4845
Adding password for user prototype.

$ npx htpasswd -v htpasswd prototype
New password:
Re-type new password:
Password for user prototype correct.

but :

$ echo 7ba4845 | npx htpasswd -iBc htpasswd prototype
Adding password for user prototype.

$ npx htpasswd -v htpasswd prototype
New password:
Re-type new password:
Password verification failed.

It's the same if i use :

$ npx htpasswd -bc htpasswd prototype 7ba4845
$ npx htpasswd -v htpasswd prototype
correct
$ echo 7ba4845 | npx htpasswd -ic htpasswd prototype
$ npx htpasswd -v htpasswd prototype
failed

but in plain text it work :

$ npx htpasswd -bpc htpasswd prototype 7ba4845
$ npx htpasswd -v htpasswd prototype
correct
$ echo 7ba4845 | npx htpasswd -ipc htpasswd prototype
$ npx htpasswd -v htpasswd prototype
correct

1000i100 avatar Mar 10 '21 00:03 1000i100

I have a feeling this never worked, as the chunk param here is a Buffer and ends with a newline.

We can create a patch like this to fix the feature:

-    password += chunk;
+    password += chunk.toString().replace(/\n/, '');

in https://github.com/gevorg/htpasswd/blob/69df40647b0fbbc93802086687510fee0a6a6dcc/src/processor.js#L124

@gevorg are you interested in releasing a new version of this module with a fix?

te-online avatar Jan 11 '23 15:01 te-online