Advertisement
Guest User

Untitled

a guest
Jul 21st, 2019
198
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.29 KB | None | 0 0
  1. <?php
  2.     require_once 'connect.php';
  3.    
  4.     $email= ((isset($_POST['email']))?sanitize($_POST['email']):'');
  5.     $email=trim($email);
  6.     $password= ((isset($_POST['password']))?sanitize($_POST['password']):'');
  7.     $password=trim($password);
  8.     $errors=array();
  9. ?>
  10.  
  11.  
  12.  
  13.  
  14.  
  15.  
  16.  
  17.  
  18.  
  19.  
  20.  
  21.  
  22.  
  23.  
  24.  
  25.  
  26.  
  27. <?php
  28.         if($_POST)
  29.         {
  30.             //form validation
  31.             if(empty($_POST['email'])|| empty($_POST['password']))
  32.             {
  33.             $errors[]='You must provide email & password.';
  34.             }
  35.        
  36.             //validate email
  37.             /* if(!filter_var($email,FILTER_VALIDATE_EMAIL)){
  38.                 $errors[]='You must enter a valid email';
  39.             } */
  40.            
  41.             //password is more than 6 characters
  42.             if(strlen($password)<6){
  43.                 $errors[]='Password must be atleast 6 characters.';
  44.             }
  45.            
  46.             //check email exist in database
  47.             $query=$db->query("SELECT * FROM register WHERE email='$email'");
  48.             $user=mysqli_fetch_assoc($query);
  49.             $userCount= mysqli_num_rows($query);
  50.             if($userCount<1){
  51.                 $errors[]= 'That email doesn\'t exist in our databse';
  52.             }
  53.            
  54.             if(!password_verify($password, $user['pass'])){
  55.                 $errors[]='Invalid Password.';
  56.                
  57.             }
  58.            
  59.             //check for errors
  60.             if(!empty($errors)){
  61.                 echo dispaly_errors($errors);
  62.             }else
  63.                 //log user in
  64.                 {
  65.                     $user_id=$user['id'];
  66.                     user_login($user_id);
  67.                 }
  68.         }
  69.        
  70.     ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement