.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
BIG file upload!
Hey guys!
I'm trying to upload a file, it works well with smaller files but with 60mb+, I get
Problems with adding a link to one position in a 'foreach' loop, please help
Hello!
Iam pretty new to programming and I wanna create a table with users from an array. It
update sql when refresh - php
hi
I have made a table (attachement)
the users can update the sql database using + or x bu
Odd or Even
Inside of a while loop I need to echo several rows of info...easy enough.
In the loop (for th
UDP Multicast question
Hey,
Im not really in the know when it comes to network related programming and activitie
SMTP server...
I recently found a tutorial online on SMTP authentification for sending emails from webpages, here i
how to load a Sys file with system load and call images?
normally you need register the module as a service with CreateService, and start the service
Update not working ... please help
Hi,
I am trying to update a row using an edit form by passing id of the row .. but it is not
Multi Level Array Problem
hi all,
For example I have array like below:
$temp = array(array('north america', 'us'
Update Myspace status with CURL
Logging in:
Code: <?php
class Myspace
{
function login($username, $pa