Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- //mysql-ctl restart
- class FModel extends CI_Model {
- //private $mysqli;
- public function __construct(){
- //$mysqli = new mysqli("localhost","ci_crud","majestic","users_login");
- }
- public function signin($user, $pass){
- $mysqli = new mysqli("localhost","ci_crud","majestic","users_login");
- $stmt = $mysqli->stmt_init();
- if ($stmt = $mysqli->prepare("SELECT * FROM user_info where username=?")) {
- $stmt->bind_param("s", $user);
- $stmt->execute();
- $stmt->bind_result($u, $p, $id);
- $stmt->fetch();
- $stmt->close();
- $mysqli->close();
- if(password_verify($pass, $p)){
- $result = [true,$u];
- return $result;
- }else{
- return [false,NULL];
- }
- }else{
- $stmt->close();
- $mysqli->close();
- return [false,NULL];
- }
- }
- public function createuser($user, $pass){
- $options =['cost'=>12,]; //kestää 250 ms luoda kryptattu salasana hash + salt
- $pass = password_hash($pass, PASSWORD_BCRYPT, $options);
- $mysqli = new mysqli("localhost","ci_crud","majestic","users_login");
- $stmt = $mysqli->stmt_init();
- if ($stmt = $mysqli->prepare("INSERT INTO user_info (username, password) VALUES (?,?)")) {
- $stmt->bind_param("ss", $user,$pass) || fail("Query failed");
- $stmt->execute() || fail("Query failed");
- $stmt->close();
- $mysqli->close();
- return true;
- }else{
- $stmt->close();
- $mysqli->close();
- return false;
- }
- }
- public function getOtsikot($aihealue){
- $result = array();
- $mysqli = new mysqli("localhost","ci_crud","majestic","users_login");
- $stmt = $mysqli->stmt_init();
- if ($stmt = $mysqli->prepare("select otsikko from lanka where aihealue=?")) {
- $stmt->bind_param("s", $aihealue);
- $stmt->execute();
- $stmt->bind_result($otsiko);
- while ($stmt->fetch()) {
- array_push($result, $otsiko);
- }
- $stmt->close();
- }else{
- }
- $mysqli->close();
- return $result;
- }
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement