.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
$_POST variable un-useable
I'm trying to use a $_POST variable in a mysql update statement but i can't use it for some unknown
Track downloads' status
Hello,
I need to make somehow, some system, to track whether downloads are completed or faile
Big Problem!! Please help
Hi Guys,
Im making a website for a friend have encountered a really annoying problem. When ev
Could Someone Please Debug This?
I was wondering if someone could debug this script for me. I realize it's not the tidest script (and
To add a field on the screen XK02.
Hi All,
How to add an additional field in the vendor change control screen XK02.
The
Convert .fdf to .pdf
I currently have a web form that uploads the form data to an .fdf file and emails it.
However
checkbox update
I am having a brain fart right now and i cant remember how to do this. if anyone could help that wou
PHP url branch??
Functionally, using PHP, I'm doing a test of login input submitted by a user via an html form in a f
Multiple Dropdown Selections
I have a form that let's a user insert a page with the ability to select categories. I want them to
Firewall / visited websites logger
Hi.
I have a firewall implementation and I want to log all the websites visited on the machine. S