How to apply .htaccess in a node.js (express) application? - node.js

I have a node.js express application and I want to authenticate users using .htaccess (part of the requirement). I have added the initial .htaccess code however, it is not working.
Here is a snapshot of my code directory structure:
Code Directory Structure
Here is the code snippet of my .htaccess file:
AuthType Basic
AuthName "Please Enter Password"
AuthBasicProvider file pam
AuthUserFile ./.htpasswd
AuthGroupFile ./.groups
Require group admins
I have two other files .htpassword and .groups that includes the password and groups.
Any help would be appreciated!

.htaccess is Apache specific.
If you want to use a library to do authentication, check basic-auth.
An example can be found in this article here: https://www.taniarascia.com/basic-authentication-for-an-express-node-app-htpasswd/

Related

.htaccess directory protection not working in nginx

I try to protect my dev web project a bit and add directory protection. ("Verzeichnisschutz" in german).
This is my .htaccess file (project/.htaccess)
AuthType Basic
AuthName "Please enter the valid auth details"
AuthUserFile .htpasswd
Require valid-user
This is my .htpasswd file (project/.htpasswd)
test:$apr1$3RWv80vU$MJFZn3DHhrB8yPNO6/TDV.
But I can still enter the website without having to enter any credentials.
I tried different browsers and inspector/private mode.
What is wrong?
Now I know why it does not work.
It is because my project runs on a nginx server and .htaccess does only work with apache.

Symfony2 simple .htaccess password protect for dev purpose

I would like to use a .htaccess file to protect my symfony2 website while developing it.
I added the following line at the beginning of my .htaccess located in /web and a .htpasswd file just next with my password.
AuthName "DĂ©veloppement"
AuthType Basic
AuthUserFile ".htpasswd"
Require valid-user
I have a Error 500 when I try to access my website. Is it possible to use a htaccess in my case ? What should I use if it is not posible ?
Assuming the 500 error is caused by these directives, the most likely reason is the path to .htpasswd. AuthUserFile says
The AuthUserFile directive sets the name of a textual file containing the list of users and passwords for user authentication. File-path is the path to the user file. If it is not absolute, it is treated as relative to the ServerRoot.
So either use an absolute path (e.g. /var/www/.htpasswd) or add the complete path starting from your document root (e.g. web/.htpasswd).
Also note the last section in AuthUserFile
Security
Make sure that the AuthUserFile is stored outside the document tree of the web-server. Do not put it in the directory that it protects. Otherwise, clients may be able to download the AuthUserFile.
This means, store the auth file somewhere else, like /etc/apache2/htpasswd.

Htaccess directory password Drupal

And sorry if this question has already been answered. But I'm trying to add a folder to my Drupal 7 installation that can be accessed only via password. I have created the folder in my FTP (and named it folder), but unfortunately I can't access this folder. I'd like the folder to look like this (like in Wordpress)
But instead I get "Page isn't working".
Br. Five
Assuming you are running Apache, try adding a .htaccess file to that folder with the following content:
Options +Indexes
When you want to password protect the directory with .htaccess you'll also have to add this:
AuthType Basic
AuthName "My Protected Area"
AuthUserFile /path/to/.htpasswd
Require valid-user

Secure site folder using .htaccess

I am using cakephp for my new project.I want to secure my site with .htaccess.Here is what i want to achieve.
If someone tries to go to my site url which is,for now www.sample.com.User should not get access without giving password or any other security method.How can i achieve this property?? Shall i eloberate this requirement??then please let me know.
Thanks in advance
With .htaccess you may protect the whole directory with password:
AuthType Basic
AuthName "Restricted Files"
AuthBasicProvider file
AuthUserFile /path/to/passwords/file/passwords
Require user myuser
you may create passwords file with the following command:
htpasswd -c /path/to/passwords/file/passwords myuser
You may complete description with good examples in Apache docs.
Original Answer: .htaccess password and forced login

.htpasswd under IIS - does it work?

I'm trying to password protect a directory on a server that's running IIS.
I've put the following in the .htaccess file in that directory -
AuthName "Restricted Area"
AuthType Basic
AuthUserFile /path/.htpasswd
AuthGroupFile /dev/null
require valid-user
I've tried a whole bunch of different paths and although it's asking for a username and password it won't take it. I've tried using the path provided by _SERVER["PATH_TRANSLATED"] but that's no help either.
Is this a problem with my path, or does IIS just not support .htpasswd?
Helicon Ape (http://www.helicontech.com/ape naturally supports .htpasswd file with all these authentication options you’ve mentioned. The software also implements a bunch of other Apache-like features. As regarding authentication, you may also be interesting in these articles: http://helicontech.blogspot.com/search/label/mod_auth
Thank you.
IIS does not support .htpasswd or .htaccess.
Natively IIS does not support the htpasswd.
You can get IISPassword for IIS from here if you really want to use
similar files under IIS.

Resources