<?php
require_once('config.php');
$error_message;
$valid = true;


$login_id = $_REQUEST['login_id'];
$new_passwod = $_REQUEST['new_passwod'];


/* $old_passwod='admin1';
$new_passwod='admin123';
$login_id='admin'; */

/* $sql = "EXEC sp_password @old = ?, @new = ?, @loginame = ?";

$procedure_params=array($old_passwod,$new_passwod,$login_id);

$stmt = sqlsrv_prepare($conn, $sql, $procedure_params);
if (!sqlsrv_execute($stmt)) {
    echo "Your code is fail!";
    die;
}
while($row = sqlsrv_fetch_array($stmt)){
    //Stuff
} */



$sql = "ALTER LOGIN \"".$login_id."\" WITH PASSWORD = '".$new_passwod."'";
$stmt = sqlsrv_prepare($conn, $sql);
if (!sqlsrv_execute($stmt)) {
    echo "Your code is fail!";
    die;
}
while($row = sqlsrv_fetch_array($stmt)){
    //Stuff
}

    


	if( $stmt ) {
		
		 sqlsrv_close( $conn);	
		 returnData();	
		} else {
		 
		 $error_message = "Transaction rolled back.<br />";
		 returnError($error_message);
	} 
	


function returnData(){
	
	$returnData = array(
	'status' => 'SUCCESS',
	'message' => 'Password Changed Successfully');
	
	echo json_encode($returnData);
}

function returnError($error_message){
	$json = array();
	
	$returnData = array(
	'status' => 'Alert',
	'message' => $error_message,
	'data' => $json);	
	
	echo json_encode($returnData);
		
	exit();
}	


?>