.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?
Did you know?Explore Trending and Topic pages for more stories like this.
<?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

php wont update my db
hello,

sorry for posting in mysql forum but i dont know where exactly is the problem but here

phpmailer class & pop.gmail.com?
Code: <?php
$mail->IsSMTP();
$mail->Host = "pop.gmail.com";

Cloud Computing?
Hello,

I was wondering if anyone could help explain this term to me. I'm starting to hear it

simplexml_load_file and rss problem
Hi,

I have a problem parsing an rss feed using simplexml_load_file - this is strange as i hav

Php If in MySql query (hiding labels if a field is empty)
Okay, I've been trying to do this for a while, and I'm finally going to ask for help so I can get th

help with image upload code
Hello,

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

Sales orders ans reservations not taken into account on MPS / MRP
Hello,

I am implementing the MPS / MRP and I have the following problem:

I ha

form variables from database help.
Hi all,

I would like to have a form that gives you options based on the results of an mysql q

problem in pagination when processing with selectbox form
Hi,

I have a search form, with select boxes, if am selecting the value from the form, it work

DirectoryIterator and Hacked Website
Hi Everyone.

My problem:
Some one has been sneaking in to my website hidden Iframes. I've

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