Advertisement
metalx1000

Change Password for User Apache

Sep 12th, 2015
595
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.67 KB | None | 0 0
  1. <?php
  2.  
  3. $file = '.htpasswds';
  4. $login = $_SERVER['REMOTE_USER'];
  5.  
  6. $pass = $_POST['pass'];
  7. $pass2 = $_POST['pass2'];
  8. $passlen = strlen($pass);
  9.  
  10. if($passlen < 6){
  11.   print "Password Not Long Enough.";
  12.   exit();
  13. }
  14.  
  15. if($pass != $pass2){
  16.   print "Passwords do not match.";
  17.   exit();
  18. }
  19.  
  20. $hash = crypt($pass, base64_encode($pass));
  21.  
  22. $current = file_get_contents($file);
  23.  
  24. //find and remove old entry
  25. $array = explode("\n",$current);
  26. foreach($array as $arr) {
  27.     if(!(preg_match("/^$login/s",$arr))) {
  28.         $output[] = $arr;
  29.     }
  30. }
  31.  
  32. $current = implode("\n",$output);
  33. $current .= "\n$login:$hash";
  34. file_put_contents($file, $current);
  35.  
  36. print "Success"
  37.  
  38.  
  39. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement