A
A
Alexey Yarkov2017-03-14 17:04:55
Nginx
Alexey Yarkov, 2017-03-14 17:04:55

How does http basic auth work?

With this script I generate htpasswd for Nginx:

#!/bin/bash

set -e

echo "**********************************************"
echo ".htpasswd file for JSDocs protection generated"
echo "**********************************************"

read -p 'Login: ' uservar

if [ -z "$uservar" ]; then
    echo "Login must by non empty string!"
    exit 1
fi

HTPASWD_LOGIN="$uservar"

HTPASWD_PASSWORD=$(openssl passwd)

str="${HTPASWD_LOGIN}:${HTPASWD_PASSWORD}"

echo $str > ./.htpasswd
sudo cp ./.htpasswd /var/www/html/
rm -f ./.htpasswd

The output line is:
login:4sdf56TUYTU.JK I start
the generation again and enter the same password. The output string is:
login:oyUYIUY4654HJH
Attention, question! And how then does Nginx know that the password is correct if the hashes are different?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Andrey Burov, 2017-03-14
@BuriK666

man7.org/linux/man-pages/man3/crypt.3.html

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question