Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Login page vs. htpasswd - Which is more secure?

Given a simple login system (register and login), which of the two choices is more secure:

  • Using htaccess and htpasswd files to store and authenticate users
  • Using php to CRUD and MySQL (or any other database really) to store the info

User info consists purely of username-password.

Of course, best-case is assumed for both options: MySQL injections are accounted for, password is md5/sha1/md5+sha1/any other means encrypted, etc.

In case you're wondering, in the first case, php will add user credentials to the htpasswd file. (see this question for an example implementation.)

like image 878
Zirak Avatar asked Apr 29 '11 14:04

Zirak


People also ask

Is htpasswd secure?

htaccess and . htpasswd are actually yielding a screen for your user name and password, it is secure. If the combination of the user name and password isn't valid, Apache will return a HTTP 403: Forbidden header, which means the request has never been passed to PHP.

Can htpasswd be hacked?

Because mistakes happen, and the . htpasswd file is a big liability. Even if you're using HTTPS, exposure of your . htpasswd file means that your passwords can be easily cracked via brute-force attacks.

What encryption does htpasswd use?

htpasswd encrypts passwords using either bcrypt, a version of MD5 modified for Apache, SHA1, or the system's crypt() routine.

What does htpasswd stand for?

htpasswd, a flat-file used to store usernames and password for basic authentication on an Apache HTTP Server.


1 Answers

I'd say always the login form (by which I assume you mean standard session-based authentication).

  • .htaccess authentication transmits the password on every request (Of course, SSL would help here)

  • .htaccess authentication doesn't have any rate limiting / brute-force protection by default in Apache

  • Logging out from .htaccess authentication is a bitch

like image 96
Pekka Avatar answered Sep 28 '22 06:09

Pekka