<commit_before><?php
	include_once 'Connect.php';

	function CustomerInsert($cid, $password, $name, $address, $phone){
		$sql = Connect();
		if ($sql->connect_error) {
			echo $sql->connect_error; 
		}
		if($sql->query("INSERT INTO Customer VALUES ('$cid', '$password', '$name', '$address', '$phone')") === FALSE){
			echo $sql->error;
		}
		Close($sql);
	}
	
	function CustomerDelete($cid){
		$sql = Connect();
		if ($sql->connect_error) {
			echo $sql->connect_error;
		}
		if($sql->query("DELETE FROM Customer WHERE cid = '$cid'") === FALSE){
			echo $sql->error;
		}
		Close($sql);
	}
	
	// returns a 2d array containing data from the Customer table
	function CustomerDisplay(){
		$sql = Connect();
		if ($sql->connect_error) {
			echo $sql->connect_error;
		}
		$result = $sql->query("SELECT * FROM Customer");
		if($result === FALSE){
			echo $sql->error;
		}
		$table = array();
		while($row = mysqli_fetch_array($result)){
			$table[] = $row;
		}
		Close($sql);
		return $table;
	}
	
	//calls CustomerInsert() but hashes password with salt first
	function CustomerRegister($cid, $password, $name, $address, $phone){
		$cost = 10;
		$salt = strtr(base64_encode(mcrypt_create_iv(16, MCRYPT_DEV_URANDOM)), '+', '.');
		$salt = sprintf("$2a$%02d$", $cost) . $salt;
		$hash = crypt($password, $salt);
		CustomerInsert($cid, $hash, $name, $address, $phone);
	}
	
	
	//returns 0 for successful login, -1 for failure
	function CustomerLogin($cid, $password){
		$r = -1;
		$sql = Connect();
		if ($sql->connect_error) {
			echo $sql->connect_error;
		}
		//this is a stupid way to retrieve hash, fix this
		$stmt = $sql->prepare("SELECT password FROM Customer WHERE cid = '$cid'");
		$r = $stmt->execute();
		if($r === FALSE){
			echo $stmt->error;
		}
		$stmt->bind_result($hash);
		if($stmt->fetch()){
			if($hash == crypt($password, $hash)){
				$r = 0;
			}
		}
		Close($sql);
		return $r;
	}
?><commit_msg>CustomerLogin() handles manager and clerk<commit_after><?php
	include_once 'Connect.php';

	function CustomerInsert($cid, $password, $name, $address, $phone){
		$sql = Connect();
		if ($sql->connect_error) {
			echo $sql->connect_error; 
		}
		if($sql->query("INSERT INTO Customer VALUES ('$cid', '$password', '$name', '$address', '$phone')") === FALSE){
			echo $sql->error;
		}
		Close($sql);
	}
	
	function CustomerDelete($cid){
		$sql = Connect();
		if ($sql->connect_error) {
			echo $sql->connect_error;
		}
		if($sql->query("DELETE FROM Customer WHERE cid = '$cid'") === FALSE){
			echo $sql->error;
		}
		Close($sql);
	}
	
	// returns a 2d array containing data from the Customer table
	function CustomerDisplay(){
		$sql = Connect();
		if ($sql->connect_error) {
			echo $sql->connect_error;
		}
		$result = $sql->query("SELECT * FROM Customer");
		if($result === FALSE){
			echo $sql->error;
		}
		$table = array();
		while($row = mysqli_fetch_array($result)){
			$table[] = $row;
		}
		Close($sql);
		return $table;
	}
	
	//calls CustomerInsert() but hashes password with salt first
	function CustomerRegister($cid, $password, $name, $address, $phone){
		$cost = 10;
		$salt = strtr(base64_encode(mcrypt_create_iv(16, MCRYPT_DEV_URANDOM)), '+', '.');
		$salt = sprintf("$2a$%02d$", $cost) . $salt;
		$hash = crypt($password, $salt);
		CustomerInsert($cid, $hash, $name, $address, $phone);
	}
	
	
	//returns 0 for successful login, 1 for clerk, 2 for manager, -1 for failure
	function CustomerLogin($cid, $password){
		$r = -1;
		if(($cid == 111111111) && ($password == "password")){
			$r = 1;//make sure manually add to db
		}else if(($cid == 222222222) && ($password == "password")){
			$r = 2;//make sure manually add to db
		}else{
			$sql = Connect();
			if ($sql->connect_error) {
				echo $sql->connect_error;
			}
			//this is a stupid way to retrieve hash, fix this
			$stmt = $sql->prepare("SELECT password FROM Customer WHERE cid = '$cid'");
			$r = $stmt->execute();
			if($r === FALSE){
				echo $stmt->error;
			}
			$stmt->bind_result($hash);
			if($stmt->fetch()){
				if($hash == crypt($password, $hash)){
					$r = 0;
				}
			}
			Close($sql);
		}
		return $r;
	}
?>
{'fraction_non_alphanumeric': 0.1972722844617633, 'fraction_numerical': 0.012177301509985387, 'mean_word_length': 3.7589803012746232, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 43, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 2, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3995867', 'n_tokens_mistral': 1652, 'n_tokens_neox': 1440, 'n_words': 364}