.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

opening a window with after form submission
I know this this forum has nothing to do with JS, but i'm trying to use it with my php script.
<

Including calander to page - will not show other months than current??
im trying to add an existaing calander onto a profile page by using Code: <?php include "

Using system() and bringing back the results
I am aware that you can use system() within PHP to execute system commands, but I was wondering if t

gmmktime or mktime
I live in the UK, i am within the GMT (with daylight saving time ie 1 hour difrence between summer a

with clause
hi all, i have a big query that usually access the same table more than once. for example, i have s

Why do I get this error?
Error:

Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or

FTP Programs
Here is a list of commonly suggested FTP Programs to use:

FileZilla
SmartFTP
CuteFTP

SCO Unix
I know this might not be the place to ask, but, can anyone tell me if SCO Unix comes with PHP built

Typedef struct vs just struct
Anyone know the rationale for using typedef for structs when a struct is itself a typedef? I have s

getting rid of quotes in strings
sick of trying to deal with them in multiple ways (entering in and taking from database, echoing, ec

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