Bonjour !
je suis ici pour que vous tentiez, SVP de résoudre mon problème : le voici.
J’ai protégé un répertoire de mon site grace à .htaccess et .htpasswd et je souhaiterais que les utilisateurs puissent s’inscrire via un formulaire qui enverait le pseudo et le mot de passe dans le fichier .htpasswd et à l’e-mail de l’inscrit.
Je suppose que l’on peut faire cela avec PHP mais je suis encore un peu dans les choux avec ce langage.
Merci !
Tu peux écrire à la fin du fichier oui… (fopen, fwrite, fclose ou file_put_contents sous PHP 5) et envoyer le mail si tu veux.
Le tout, ce sera de bien gérer les erreurs parce qu’écrire dans un fichier de configuration c’est toujours sensible.
merci pour ta réponse !
mais je ne sais pas à quoi tu fais allusion avec toutes ces balises, car je vais à peine de mettre un pied dans la programation php. Ne pourrais tu pas m’expliquer et/ou me faire un petit bout de code.
merci
Genre:
<?php
if (!isset($_POST['user']) || !isset($_POST['pwd'])) {
echo 'erreur : pas d\'utilisateur', "\n";
} elseif (false === ( $fp = fopen('.htpasswd', 'ab'))) {
echo 'erreur : impossible d\'ouvrir le fichier', "\n";
} else {
// + encodage du mot de passe
fprintf($fp, '%s:%s' . "\n", $_POST['user'], $_POST['pwd']);
fclose($fp);
echo 'succès: Sans-Nom, tu es trop un chef!', "\n";
}
?>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
login: <input type="text" name="user" />
password: <input type="password" name="pwd" />
<input type="submit" />
</form>
Ca devrait faire l’affaire pour la base. Pour le reste, faut crypter le mot de passe sinon ça passe pas…
merci, ça marche !
à propos du cryptage, j’ai un code pour crypter les mots de passe :
<p>
<?php
if (isset($_POST['login']) AND isset($_POST['pass']))
{
$login = $_POST['login'];
$pass_crypte = crypt($_POST['pass']); // On crypte le mot de passe
echo 'Ligne à copier dans le .htpasswd :<br />' . $login . ':' . $pass_crypte;
}
else // On n'a pas encore rempli le formulaire
{
?>
</p>
<p>Entrez votre login et votre mot de passe pour le crypter.</p>
<form method="post">
<p>
Login : <input type="text" name="login"><br />
Mot de passe : <input type="text" name="pass"><br /><br />
<input type="submit" value="Crypter !">
</p>
</form>
<?php
}
?>
mais je ne sais pas comment dire a ton code d’utiliser pour rentrer le mot de passe dans le fichier .htaccess
merci !
Remplace juste $_POST[‘pass’] par crypt($_POST[‘pass’]) dans le code de Sans-Nom.
merci mais je ne trouve pas $_POST[‘pass’]
pourrait-tu me l’indiquer ? STP
pwd pardon.
<?php
if (!isset($_POST['user']) || !isset($_POST['pwd'])) {
echo 'erreur : pas d\'utilisateur', "\n";
} elseif (false === ( $fp = fopen('.htpasswd', 'ab'))) {
echo 'erreur : impossible d\'ouvrir le fichier', "\n";
} else {
// + encodage du mot de passe
fprintf($fp, '%s:%s' . "\n", $_POST['user'], crypt($_POST['pwd']));
fclose($fp);
echo 'succès: Sans-Nom, tu es trop un chef!', "\n";
}
?>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
login: <input type="text" name="user" />
password: <input type="password" name="pwd" />
<input type="submit" />
</form>
Merci, ça marche !
est-ce possible d’en envoyer une copie à l’e-mail "adresse@123.com " en appuyant sur ce même bouton ?
Merci !
PS: désolé de poser toutes ces questions mais je suis plus que débutant en la matière mais grace à vous, j’apprends petit à petit les balises,…
Merci !
Oui, voir fonction mail() sur php.net .
Juste une précision, on ne parle pas de balise en PHP ni dans d’autres langages impératifs, on parle de fonctions dans ce cas.
_benj
Mai 24, 2007, 10:46
13
alors le concept c’est quoi ? permettre aux gens d’accéder a une partie du site censée être privée ? :neutre:
pour aller plus vite tu devrais plutôt utiliser system et appeller htpasswd2 -b /path/to/file user password
_benj:
alors le concept c’est quoi ? permettre aux gens d’accéder a une partie du site censée être privée ? :neutre:
pour aller plus vite tu devrais plutôt utiliser system et appeller htpasswd2 -b /path/to/file user password
s’il y a une méthode à retenir, c’est celle-ci !
Bonjour !
excusez-moi pour le délai de réponse.
j’ai cherché pour la fonction mail() mais je n’arrive pas à la mettre en place sur le bouton. Merci !
PS: A benj c’est quoi htpasswd2 -b /path/to/file user password ? merci!
_benj
Juin 2, 2007, 12:56
16
c’est une commande système.
htpasswd2
SYNOPSIS
htpasswd [ -c ] [ -m ] [ -D ] passwdfile username
htpasswd -b [ -c ] [ -m | -d | -p | -s ] [ -D ] passwdfile
username password
htpasswd -n [ -m | -d | -s | -p ] username
htpasswd -nb [ -m | -d | -s | -p ] username password
SUMMARY
htpasswd is used to create and update the flat-files used
to store usernames and password for basic authentication
of HTTP users. If htpasswd cannot access a file, such as
not being able to write to the output file or not being
able to read the file in order to update it, it returns an
error status and makes no changes.
Resources available from the Apache HTTP server can be
restricted to just the users listed in the files created
by htpasswd. This program can only manage usernames and
passwords stored in a flat-file. It can encrypt and dis
play password information for use in other types of data
stores, though. To use a DBM database see dbmmanage.
htpasswd encrypts passwords using either a version of MD5
modified for Apache, or the system's crypt() routine.
Files managed by htpasswd may contain both types of pass
words; some user records may have MD5-encrypted passwords
while others in the same file may have passwords encrypted
with crypt().
This manual page only lists the command line arguments.
For details of the directives necessary to configure user
authentication in httpd see the Apache manual, which is
part of the Apache distribution or can be found at
[httpd.apache.org...](http://httpd.apache.org/.)
OPTIONS
-b Use batch mode; i.e., get the password from
the command line rather than prompting for
the command line, since the passwdfile argu
ment (usually the first one) is omitted. It
cannot be combined with the -c option.
-m Use MD5 encryption for passwords. On Win
dows, Netware and TPF, this is the default.
-d Use crypt() encryption for passwords. The
default on all platforms but Windows, Net
ware and TPF. Though possibly supported by
htpasswd on all platforms, it is not sup
ported by the httpd server on Windows, Net
ware and TPF.
-s Use SHA encryption for passwords. Facili
tates migration from/to Netscape servers
using the LDAP Directory Interchange Format
(ldif).
-p Use plaintext passwords. Though htpasswd
will support creation on all platforms, the
httpd daemon will only accept plain text
passwords on Windows, Netware and TPF.
-D Delete user. If the username exists in the
specified htpasswd file, it will be deleted.
passwdfile
Name of the file to contain the user name
and password. If -c is given, this file is
created if it does not already exist, or
rewritten and truncated if it does exist.
username
The username to create or update in passwd
file. If username does not exist in this
file, an entry is added. If it does exist,
the password is changed.
password
The plaintext password to be encrypted and
stored in the file. Only used with the -b
flag.
EXIT STATUS
htpasswd returns a zero status ("true") if the username
and password have been successfully added or updated in
the passwdfile. htpasswd returns 1 if it encounters some
problem accessing files, 2 if there was a syntax problem
with the command line, 3 if the password was entered
interactively and the verification entry didn't match, 4
tem, the password will be encrypted using the modified
Apache MD5 algorithm; otherwise, the system's crypt() rou
tine will be used. If the file does not exist, htpasswd
will do nothing except return an error.
htpasswd -c /home/doe/public_html/.htpasswd jane
Creates a new file and stores a record in it for user
jane. The user is prompted for the password. If the file
exists and cannot be read, or cannot be written, it is not
altered and htpasswd will display a message and return an
error status.
htpasswd -mb /usr/web/.htpasswd-all jones Pwd4Steve
Encrypts the password from the command line (Pwd4Steve)
using the MD5 algorithm, and stores it in the specified
file.
SECURITY CONSIDERATIONS
Web password files such as those managed by htpasswd
should not be within the Web server's URI space -- that
is, they should not be fetchable with a browser.
The use of the -b option is discouraged, since when it is
used the unencrypted password appears on the command line.
RESTRICTIONS
On the Windows and MPE platforms, passwords encrypted with
htpasswd are limited to no more than 255 characters in
length. Longer passwords will be truncated to 255 charac
ters.
The MD5 algorithm used by htpasswd is specific to the
Apache software; passwords encrypted using it will not be
usable with other Web servers.
Usernames are limited to 255 bytes and may not include the
character :.
Bonjour !
Merci !
mais personne ne peux m’aider en ce problème ?
comment envoyer le résultat du formulaire à mon e-mail : anonymous@anonym.net
et l’inscrire en plus dans le fichier .htpasswd en le cryptant ?
Merci !
Regarde du côté de la fonction mail(), et de la fonction system() …
Sinon tu peux faire un système qui va demander à avoir l’accès, et t’enverras un mail avec les paramètres voir la commande à éxécuter.
Edité le 03/06/2007 à 23:13
merci,
mais je suis débutant en php,
et j’ai beau chercher,
à aucun endroit, on explique comment mettre ces fonction en plus,
pour qu’elles se déclenche par un clic sur le bouton.
J’ai bien trouver un petit bout de code pour envoyer un email mais je ne sais pas comment le mettre :
le voici ->
<?php
mail('email_destinataire', 'sujet', 'message');
?>
et voici le code de ma page,
<?php
if (!isset($_POST['user']) || !isset($_POST['pwd'])) {
echo 'erreur : pas d\'utilisateur', "\n";
} elseif (false === ( $fp = fopen('/home/f/l/o/florent73/.htpasswd', 'ab'))) {
echo 'erreur : impossible d\'ouvrir le fichier', "\n";
} else {
// + encodage du mot de passe
fprintf($fp, '%s:%s' . "\n", $_POST['user'], crypt($_POST['pwd']));
fclose($fp);
echo 'succès: Sans-Nom, tu es trop un chef!', "\n";
}
?>
login:
password:
Merci de m’aider !
Tu es débutant certes, mais tu sais lire quand même… si tu n’as pas la moindre idée en lisant le code qu’on t’a écrit, on n’y peut pas plus hein