daily pastebin goal
20%
SHARE
TWEET

Untitled

a guest Apr 27th, 2016 70 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2. //mysql-ctl restart
  3.  
  4.  
  5.  
  6. class FModel extends CI_Model {
  7.    
  8.     //private $mysqli;
  9.    
  10.     public function __construct(){
  11.         //$mysqli = new mysqli("localhost","ci_crud","majestic","users_login");
  12.     }
  13.    
  14.     public function signin($user, $pass){
  15.         $mysqli = new mysqli("localhost","ci_crud","majestic","users_login");
  16.         $stmt = $mysqli->stmt_init();
  17.         if ($stmt = $mysqli->prepare("SELECT * FROM user_info where username=?")) {
  18.             $stmt->bind_param("s", $user);
  19.             $stmt->execute();
  20.             $stmt->bind_result($u, $p, $id);
  21.             $stmt->fetch();
  22.             $stmt->close();
  23.             $mysqli->close();
  24.             if(password_verify($pass, $p)){
  25.                 $result = [true,$u];
  26.                 return $result;
  27.             }else{
  28.                 return [false,NULL];
  29.             }
  30.         }else{
  31.             $stmt->close();
  32.             $mysqli->close();
  33.             return [false,NULL];
  34.         }
  35.     }
  36.    
  37.     public function createuser($user, $pass){
  38.         $options =['cost'=>12,]; //kest√§√§ 250 ms luoda kryptattu salasana hash + salt
  39.         $pass = password_hash($pass, PASSWORD_BCRYPT, $options);
  40.         $mysqli = new mysqli("localhost","ci_crud","majestic","users_login");
  41.         $stmt = $mysqli->stmt_init();
  42.         if ($stmt = $mysqli->prepare("INSERT INTO user_info (username, password) VALUES (?,?)")) {
  43.             $stmt->bind_param("ss", $user,$pass) || fail("Query failed");
  44.             $stmt->execute() || fail("Query failed");
  45.            $stmt->close();
  46.            $mysqli->close();
  47.            return true;
  48.         }else{
  49.             $stmt->close();
  50.             $mysqli->close();
  51.             return false;
  52.         }
  53.     }
  54.    
  55.     public function getOtsikot($aihealue){
  56.         $result = array();
  57.         $mysqli = new mysqli("localhost","ci_crud","majestic","users_login");
  58.         $stmt = $mysqli->stmt_init();
  59.         if ($stmt = $mysqli->prepare("select otsikko from lanka where aihealue=?")) {
  60.             $stmt->bind_param("s", $aihealue);
  61.             $stmt->execute();
  62.             $stmt->bind_result($otsiko);
  63.             while ($stmt->fetch()) {
  64.                 array_push($result, $otsiko);
  65.             }
  66.            $stmt->close();
  67.         }else{
  68.         }
  69.         $mysqli->close();
  70.         return $result;
  71.     }
  72.    
  73.    
  74. }
  75.  
  76. ?>
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top