Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Web Interface for .htaccess maintenance using PHP

Status
Not open for further replies.

jimoblak

Instructor
Joined
Oct 23, 2001
Messages
3,620
Location
US
This was originally posted on Mar 1, 2001 but there was never an answer. I'm looking for a simple php script to generate the htpassword file like what is accomplished with the online generator on
Any ideas?

///////////////

bkodarapu (IS/IT--Manageme) Mar 1, 2001
hi everyone,

i'm trying to develop a web form to maintain users in .htaccess files. anybody tried this before?? if so, please help me with my development.

thanks in advance.



- - picklefish - -
 
quoted from :

Martin F.
19-Apr-2003 04:41

To modify an existing .htpasswd or to create a new one:
-------------------------------------------------------

$file = '.htpasswd';

// Read the file into the array $passwords
// This part is not necessary if you don't have an existing .htpasswd and want to create a new one.
$lines = file($file);
foreach($lines as $nokey => $line)
{
$array = explode(':',$line);
$user = $array[0];
$password = chop($array[1]);
$passwords[$user] = $password;
}
// Now you have the array $passwords with the users as keys and the (encrypted) passwords as values.

// Add a user
$newuser = 'foo';
$newpass = 'bar';
// Next part to generate a random salt with letters and/or numbers
mt_srand((double)microtime()*1000000);
$chars = array_merge(range('a','z'),range('A','Z'),range(0,9));
for($i=0;$i<2;$i++)
{
$salt .= $chars[mt_rand(0,count($chars)-1)];
}
// Salt $salt created
// Now add the user
$passwords[$newuser] = crypt($newpass,$salt);
// Now the array $passwords contains the existing users and (encrypted) passwords from the file and the new user (and the encrypted password).

// Delete a user
$deleteuser = 'foobar';
unset($passwords[$deleteuser]);

// Update the file
$filehandle = fopen($file,'w');
foreach($passwords as $user => $password)
{
fputs($filehandle, &quot;$user:$password\n&quot;);
}
fclose($filehandle);



so, u basically have to create a random number (?) and then crypt(); the text password with the random number, like crypt($text, $rnd);
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top