.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
29
Other forums
need help to creat database
Hello Team, please guys i am stuck from three days with paypal issue for IPN but no luck yet now i w
need help modifying script
Hi guys,
I'm fairly new to php and am having a bit of trouble modifying a script.
This
random generation
hi
i need help with generating this
numbers from 1-12
i want to generate in ran
PHP search multiple input field box help
I am having a problem with my search script. At current it will simply search by a selected date whi
using variables in another page
I have a test database set up on localhost. I have a form that I can type a name into, hit the butto
How do I replace any number of character occurences with one occurrence?
How do I replace any number of character occurences with one occurrence?
Let's say I have:
TCP Sending Unsigned Char...
Hi...
I want to send over tcp/ip some data, i have the data in hexadecimal, and when i tr
How to give the privillege for triggers?
Hi,
How to give the privillage for triggers to particular user?
Please let me
Help With editting and deleting form
Hallo !!
So look at this image :
http://img194.imageshack.us/img194/8272/snapshot5f.pn
File upload issues
Hi Guys,
Can anyone see any issues with this code:
Code: $setImage= 'productimages/' . dat