page de connexion par rapport à htpasswd - Ce qui est plus sûr?
Question
Avec un système de connexion simple (enregistrer et login), lequel des deux choix est plus sûr:
- Utilisation de fichiers htaccess et htpasswd aux utilisateurs de stocker et authentifient
- Utilisation de php pour CRUD et MySQL (ou toute autre base de données vraiment) pour stocker les informations
Infos utilisateur se compose uniquement de nom d'utilisateur-mot de passe.
Bien sûr, le meilleur cas est supposé pour les deux options: injections de MySQL sont prises en compte, le mot de passe est md5 / SHA1 / md5 + SHA1 / tout autre moyen crypté, etc
.Dans le cas où vous vous demandez, dans le premier cas, php ajoutera les informations d'identification de l'utilisateur du fichier htpasswd. (Voir cette question pour un exemple d'implémentation.)
La solution
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 ApacheLogging out from
.htaccess
authentication is a bitch
Autres conseils
There is pretty much no difference between the 2 ways in terms of in flight security. but Pekka's concerns are all valid. If you just want to use HTTP Basic Auth (ie the popup box) as opposed to a login form, you can do it via PHP. by looking for $_SERVER['PHP_AUTH_USER']
and if you don't find it send back a 401 response such as:
if (!isset($_SERVER['PHP_AUTH_USER'])) {
header('WWW-Authenticate: Basic realm="MY REALM"');
header('HTTP/1.0 401 Unauthorized');
echo 'Please Contact us if you are having problems logging in';
exit;
} else {
//not their first time through
//check their username and password here
$username = trim($_SERVER['PHP_AUTH_USER']);
$password = trim($_SERVER['PHP_AUTH_PW']);
//do login
}
This way you can do rate limit/brute force detection. Set a session, so that the passwords isn't sent with each request, and makes logging the user out and tracking them way easier.