changepassword.php 778 B

1234567891011121314151617181920212223242526
  1. <?php
  2. // Init owncloud
  3. require_once('../../lib/base.php');
  4. $username = isset($_POST["username"]) ? $_POST["username"] : OC_User::getUser();
  5. $password = $_POST["password"];
  6. $oldPassword=isset($_POST["oldpassword"])?$_POST["oldpassword"]:'';
  7. // Check if we are a user
  8. OC_JSON::checkLoggedIn();
  9. if( (!OC_Group::inGroup( OC_User::getUser(), 'admin' ) && ($username!=OC_User::getUser() || !OC_User::checkPassword($username,$oldPassword)))) {
  10. OC_JSON::error( array( "data" => array( "message" => "Authentication error" )));
  11. exit();
  12. }
  13. // Return Success story
  14. if( OC_User::setPassword( $username, $password )){
  15. OC_JSON::success(array("data" => array( "username" => $username )));
  16. }
  17. else{
  18. OC_JSON::error(array("data" => array( "message" => "Unable to change password" )));
  19. }
  20. ?>