![]() |
removing user from htpasswd via php
anyone have a snippet of code I could borrow to do this?
or at least point me in the right direction? Thanks :) |
|
30$ for a script like that? could code one quicker
|
that's a little over my .20 cent budget
|
Quote:
Tomud |
steal / use the ccbill or epoch one that everyone has.
|
Quote:
and where can I get it ? :\ |
Quote:
I bet you $60 you can't code even a hello script faster than I can swipe my VISA for $30. Tell me when you want to fire the gun :D |
shit, got everything working..
sign up, recover pass and cancel (remove from db) except for the removing from htpasswd part ima go crazy :) |
If anyone cares... I found a solution. Now to integrate it into my script
http://www.thewebmasters.net/php/Htpasswd.phtml ;) Thanks to everyone who tried to help me. I appreciate it. |
Thanks for the "LINK" haha ;)
|
A simple version
<form action=<?=$PHP_SELF?> method=post>
Username <input name=username><p> Password <input name=password></p> | Add <input type=radio name=do_what value=Add> | Modify <input type=radio name=do_what value=Modify> | Delete <input type=radio name=do_what value=Delete> |<br> <input type=submit value=submit> </form> <? // find path and filename in .htaccess // change access permission of filename to to allow write $htaccess_file = "path_of_file/filename"; $username = trim($_POST["username"]); // from yout post form $password = trim($_POST["password"]); // from your post form $action = $_POST["do_what"]; // from your post form $user_string = $username . ":" . crypt($password) ."\n"; if($action == "Add") { $fp=fopen($htaccess_file, "a+"); if ($fp) { while (!feof($fp)) { $htpassinfo = fgets($fp, 4096); list($ht_username, $ht_password) = explode(":", $htpassinfo); if(trim($username) == trim($ht_username)) { echo "Username $username is already existed"; exit; } } if (fwrite($fp, $user_string) === FALSE) { echo "FAIL to Add"; fclose($fp); exit; } fclose($fp); echo "Add Successful"; } } else { $fp=fopen($htaccess_file, "r"); if ($fp) { $i=0; while (!feof($fp)) { $htpassinfo = fgets($fp, 4096); list($ht_username, $ht_password) = explode(":", $htpassinfo); if(trim($username) == trim($ht_username)) { if($action == "Delete") { $htlist[$i] = ""; $msg = "Deleted"; } else if($action == "Modify") { $htlist[$i] = $user_string; $msg = "Modified"; } else { $htlist[$i] = $htpassinfo; } } else { $htlist[$i] = $htpassinfo; } $i++; } fclose($fp); } else { echo "fail to open file"; exit; } $fp=fopen($htaccess_file, "w"); if ($fp) { for($i=0;$i<count($htlist);$i++) { fputs($fp, $htlist[$i]); } echo $msg; } } ?> |
include("class.Htpasswd.php3");
$UserID = "$user"; $Htpasswd = new Htpasswd; $Htpasswd->initialize("/home/topsecretdomainbeforewebdirectory/.htpasswd"); if(!($Htpasswd->EXISTS)) { #O KNOEZ !! exit; } if($Htpasswd->deleteUser($UserID)) |
grep -Ev "^desired_username:" .htpasswd > .htpasswd.tmp;mv -f .htpasswd.tmp .htpasswd
you can use PHP's exec() function to execute this shell command... you will have to use full paths of course |
Quote:
Thanks for the post though :)) |
ok, people asked about code.
The code above I posted is a working code, you need to change the path and htaccess file permission, easy way is in command line -- chmod 666 filename that's it |
Quote:
|
Just be careful you don't end up with two processes writing the password file at the same time. None of the methods posted in here use locking.
|
| All times are GMT -7. The time now is 05:53 PM. |
Powered by vBulletin® Version 3.8.8
Copyright ©2000 - 2025, vBulletin Solutions, Inc.
©2000-, AI Media Network Inc123