mbuckley2000 Posted November 21, 2009 Share Posted November 21, 2009 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; } Link to comment https://forums.phpfreaks.com/topic/182390-htpasswd-registration-form/ Share on other sites More sharing options...
mbuckley2000 Posted November 21, 2009 Author Share Posted November 21, 2009 Please help someone.. I really need this for my website. Link to comment https://forums.phpfreaks.com/topic/182390-htpasswd-registration-form/#findComment-962862 Share on other sites More sharing options...
QuickOldCar Posted January 1, 2015 Share Posted January 1, 2015 Use a normal user log in using password-hash() with sessions Link to comment https://forums.phpfreaks.com/topic/182390-htpasswd-registration-form/#findComment-1501448 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.