<?php
	session_start();

	$userID = $_SESSION['marry_userID'];
	$userPW = $_SESSION['marry_userPW'];
	$oldPW = $_POST['oldPW'];
	$newPW = $_POST['newPW'];
	$newPWC = $_POST['newPWC'];
	$dbp = "userDB/";
	$filename = $dbp . $userID . ".txt";

	//read userfile
	$file = fopen($filename,"r");
		$readed = fread($file,filesize($filename));
		fclose($file);
	$rearray = explode("\r\n",$readed);
	
	if(password_verify($userPW, $rearray[0]) && password_verify($oldPW, $rearray[0]) && $newPW == $newPWC) {
		$content = 
			password_hash($newPWC, PASSWORD_DEFAULT) . "\r\n" .
			$rearray[1] . "\r\n" .
			$rearray[2] . "\r\n" .
			$rearray[3] . "\r\n" .
			$rearray[4] . "\r\n" .
			$rearray[5] . "\r\n" .
			$rearray[6] . "\r\n" .
			$rearray[7];
	
		$opn = fopen($filename,"w");
		$write = $content;
		fputs($opn,$write);
		fclose($opn);
		echo "changed succsfully!";
	}	
	else {
		echo "confirm wrong, password wrong, or else wrong";
	}
?>