.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
How to secure my login data to my database?
Hi there,
It may be a stupid question but I don't know how to secure my login data to my data
registration form
first time posting. did some searches but didnt find exactly what i am looking for. dont flame cause
LIMIT $start, 10... how to pass last value queried into next page with GET??
Ok I know how to display the first or last 10 results of a query...
$result = mysql_query(&q
Question handling xml data
Hello,
I have sucessfull followed this tutorial
http://www.phpfreaks.com/tutorial/handlin
Just cannot get 'area' to submit to db using same php code as already used
Basically all i have done is just modified some code and added an area section.
The form is allre
Month String to Numeric?
Hi guys,
Given a month as a string, is there a simple way to find the numeric representation
cPanel API
Hi Guys,
Need a little guidance. I'm trying to get my script to communicate with cPanel (or W
GET vs SUBMIT Button to show sections on one index.php page?
Just curious if one of these ways is better (i.e. more efficient) than the other.
I have a
Help With editting and deleting form
Hallo !!
So look at this image :
http://img194.imageshack.us/img194/8272/snapshot5f.pn
Need help: how to catch acess of undefined class properties
Hello. I am learning OO with PHP and have hit a problem.
Some code runs as perfectly valid code,