.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

Retail terminologys not been altered after activing Retail System
Hi, All

After I active Retail System via TCode SWF5, the terms does not been changed, th

Problem with DB connection
Hello there! I'm new to this forum and I'm new to PHP coding also. I wrote something that doesn't ma

Is there a function ... auto send IP
Is there some function that can be sent to a ddns service that returns the ip address of a ddns forw

need help with mail()
hi i want to send an email with attaching pdf file using php. i have the following script but the pr

Empty text file when there is over XXXX lines of text.

define("RANDOM_FILE","/public_html/random.txt");
$randomEntry = "

Looking for help on using joining mysql tables and php....
Does anyone have any good links to references on how to pull mysql data, through joining tables and

http to https
Hi,

Is there any specific method/condition to move an http:// page to https:// ?

MYSQL INSERT ID NOT WORKING
Code: $id = mysql_insert_id();
header("Location: ./?view=$id");
Why $id pulling blan

Help please - How to validate from 2 possible answers
Hi

I hope somebody can help me with what will probably be really simple, I'm pulling my hair

dynamic table with forms
I have a table that is populated with mysql data and in teh first column there is a raido button tha

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