Mega Code Archive

 
Categories / Php / User Management
 

SysOp

<? function checkUser($user, $pass) { $fp = fopen("filename", "r"); $auth = false; while (!feof($fp)) { $parts = explode("||:|:||", trim(fgets($fp, 1024))); if ($parts[0] == substr(crypt($user, "mn"), 2)) { if ($parts[1] == substr(crypt($pass, "jh"), 2)) { $auth = true; break; } } } fclose($fp); return $auth; } function addUser($user, $pass, $email) { $fp = fopen("filename", "r"); $user = substr(crypt(trim($user), "mn"), 2); while (!feof($fp)) { $parts = explode("||:|:||", trim(fgets($fp, 1024))); if ($parts[0] == $user) { return 0; exit; } } fclose($fp); $fp = fopen("filename", "a"); $pass = substr(crypt(trim($pass), "jh"), 2); $email = trim($email); $string = $user."||:|:||".$pass."||:|:||".$email."\n"; fwrite ($fp, $string); fclose($fp); return 1; } function findUser($user) { $fp = fopen("filename", "r"); $found = false; $i = 0; while (!feof($fp)) { $parts = explode("||:|:||", trim(fgets($fp, 1024))); if ($parts[0] == substr(crypt($user, "mn"), 2)) { print ("User <b><i>$user</i></b> found at line <b>$i</b>:<br>$parts[0]<br>$parts[1]<br>$parts[2]"); break; } $i++; } } function deleteUser($user) { $user = substr(crypt(trim($user), "mn"), 2); $newfile[0] = ""; $content = file(""); $i = 0; for(; $i < count($content); $i++) { $parts = explode("||:|:||", trim($content[$i])); if (!$parts[0] == $user) { $newfile[$i] = $content[$i]; } } $fp = fopen("filename", "w") or die ("Could not open file for writing"); for ($i = 0; $i < count($newfile); $i++) { fwrite($fp, $newfile[$i]."\n"); } fclose ($fp); } ?>