aboutsummaryrefslogtreecommitdiffstats
path: root/settings/ajax/changepassword.php
blob: f568d3ef876c4b2158169201ba44220e5553dab6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
<?php

// Init owncloud
require_once('../../lib/base.php');

$l=new OC_L10N('settings');

// We send json data
header( "Content-Type: application/jsonrequest" );

// Check if we are a user
if( !OC_USER::isLoggedIn()){
	echo json_encode( array( "status" => "error", "data" => array( "message" => $l->t( "Authentication error" ) )));
	exit();
}

// Get data
if( !isset( $_POST["password"] ) && !isset( $_POST["oldpassword"] )){
	echo json_encode( array( "status" => "error", "data" => array( "message" => $l->t( "You have to enter the old and the new password!" ) )));
	exit();
}

// Check if the old password is correct
if( !OC_USER::checkPassword( $_SESSION["user_id"], $_POST["oldpassword"] )){
	echo json_encode( array( "status" => "error", "data" => array( "message" => $l->t("Your old password is wrong!") )));
	exit();
}

// Change password
if( OC_USER::setPassword( $_SESSION["user_id"], $_POST["password"] )){
	echo json_encode( array( "status" => "success", "data" => array( "message" => $l->t("Password changed") )));
}
else{
	echo json_encode( array( "status" => "error", "data" => array( "message" => $l->t("Unable to change password") )));
}

?>