<?php
	$udir = "UserDB/";
	$username = $_POST['userID'];
	$enteredpw = $_POST['userPW'];
	$passconfirm = $_POST['userPWC'];
	$gender = $_POST['userGN'];
	
	$exist = file_exists($udir . $username . ".txt");
	$valid = empty($username);
	$valid2 = empty($passconfirm);
	
	if($enteredpw == $passconfirm && $exist == false && $valid == false && $valid2 == false) {
		$hashgen = password_hash($passconfirm, PASSWORD_DEFAULT);
		$content = "$hashgen" . "\r\n" . "$gender";
		
		$opn = fopen($udir . $username . ".txt","w");
		$write = $content;
		fputs($opn,$write);
		fclose($opn);
		
		echo "Register Complete!";
	}
	else {
		echo "Password And Password Confirm Do not match or this account already exist or invalid register";
	}
?>