.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

Motivational Posters
Hello,

I wonder how can i do them in php. Are there any sample codes that you can show me?

DOMDocument
Hello All,

I need to take an XML document, modify some of the nodes in it and then perform a

SOAP Issue
Hi,

I am facing some understanding problem with SOAP basic.kindly recommend some SOAP expert.

Count Session and Trigger Events
I am New in PHP, seeking a method to count logged users by counting the sessions or any …, is

Opening Multiple Files/Links in Order.
I want to open links in order/one-by-one and check each for a specific string.

Example:
I

SAP BCS. BPS
Hi all,

I am seeking reading note on the following in BW

BCS, BPS
ADVANCE

Custom array sort? asc then desc
Any ideas how I could sort this array? I've been trying for a while. Maybe with usort, but I have no

Warning: session_start() headers already sent error - Driving me Nuts!
I am trying my sister in laws site and I keep getting an error with my coding. I am more of a design

blank page.... nothing is happening.
I'm new to a lot of this but in the last 24hrs have learned a lot.
Installed latest version of my

update post issues
I am trying to create an update to a post function, while the update does occur, the page routing an

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