.htpasswd Registration Form


Posted on 16th Feb 2014 07:03 pm by admin

Hi,
I wanted to make an htpasswd registration form.
I found this code on the internet but have no idea how to use it.
Can anyone help?
<?php
// Register User
function regUser() {




$filename = 'members/password/.htpasswd';
$data = $_POST['username'].":".htpasswd($_POST['password'])."n";
if (is_writable($filename)) {


if (!$handle = fopen($filename, 'a')) {
echo "Cannot open file ($filename)";
exit;
}


if (fwrite($handle, $data) === FALSE) {
echo "Cannot write to file ($filename)";
exit;
}

// echo "Success, wrote ($data) to file ($filename)";

fclose($handle);

} else {

echo "The file $filename is not writable";
}

}

// Show all Users and Passwords
function showUser()
{


$file = file('members/password/.htpasswd');
$array = array();
$count = count($file);
for ($i = 0; $i < $count; $i++)
{
list($username, $password) = explode(':', $file[$i]);
$array[] = array("username" => $username, "password" => $password);
}

return $array;
}
function delUser($username) {

$fileName = file('members/password/.htpasswd');
$pattern = "/". $username."/";

foreach ($fileName as $key => $value) {

if(preg_match($pattern, $value)) { $line = $key; }
}


unset($fileName[$line]);

if (!$fp = fopen('members/password/.htpasswd', 'w+'))
{

print "Cannot open file ($fileName)";

exit;
}


if($fp)
{

foreach($fileName as $line) { fwrite($fp,$line); }

fclose($fp);
}

}


// Encrypt Passwords
function htpasswd($pass)

{

$pass = crypt(trim($pass),base64_encode(CRYPT_STD_DES));

return $pass;

}

No comments posted yet

Your Answer:

Login to answer
104 Like 29 Dislike
Previous forums Next forums
Other forums

Which practice of iteration through containers is preferred
In the "real world" what kind of loop do most people use to iterate through a container like a vecto

values not being entered into table
hi. I;ve created a form, so that when a user enters data into it, it gets added to a table in a data

Join Query Help
Hi all,

I am having problems with the below code, which we shall call 'my first join query'!

Include ("Absolute Path") of a file?
I'm not sure what I'm doing wrong. I am writing my php code in the same directory of the file that

All possible combinations of String in PL/SQL
Hi All,

Could you please explain the logic of getting all possible combinations of String

Why use interfaces in PHP (OOP)
I am learning OOP in PHP and its been a pretty good learning experience so far. What I didn't unders

help with image upload code
Hello,

right now this code I have resizes images and then places them into the uploads folder

Results from Db outputted twice
Hey guys.. for come reason my data is outputted twise shown in the image below and i cant figure out

About imagecopyresampled()
Hello,

I am looking to use this function to resize parts of an image to a fixed thumbnail siz

Members Only
Hi all, for my website i have a members area only which on members can veiw, but at the moment anyon

Sign up to write
Sign up now if you have flare of writing..
Login   |   Register
Follow Us
Indyaspeak @ Facebook Indyaspeak @ Twitter Indyaspeak @ Pinterest RSS



Play Free Quiz and Win Cash