Welcome Guest, Not a member yet? Register   Sign In
Simple Secure Library Issues
#1

[eluser]seontist[/eluser]
Hi all,

I am new to codeigniter and have managed to get through all the tutorials with some difficulty, due to some outdated stuff.
Anyway, i am experimenting with Simple Secure Library to create a login for a new site i am building but keep running into the same error here is my controller,
Code:
class Signup extends CI_Controller
{
    function __construct()
    {
   parent::__construct();    
     $this->load->library('SimpleLoginSecure');
}    
function index()
{
  $this->load->view('signup');  
}

function create_user()
{
  
  $this->load->library('form_validation');
    
  $useremail= $this->input->post('user_email');
  $password = $this->input->post('user_pass');


  $this->simpleloginsecure->create('$useremail', '$password!', false);
  
  //$this->load->view('signup');
  
  

}
  
}
and the view
Code:
<!DOCTYPE html>
&lt;html&gt;
&lt;head&gt;
&lt;title&gt;SIGNUP VIEW&lt;/title&gt;
&lt;/head&gt;
&lt;body&gt;
The content of the SIGNUP VIEW......

<p>Login Info</p>
&lt;?php
echo form_open('signup/create_user');
echo form_input('user_email', set_value('email', 'Email'));
echo form_input('user_pass', set_value('password', 'Password'));
echo form_input('password2', 'Password Confirm');

echo form_submit('submit', 'Create Acccount');

//echo $username;
//echo $password;

?&gt;
<p>&lt;?php //echo validation_errors('<p class="error">'); ?&gt;</p>

&lt;/body&gt;
&lt;/html&gt;
and finally the error.

A PHP Error was encountered

Severity: Notice

Message: Undefined property: Signup::$db

Filename: libraries/SimpleLoginSecure.php

Line Number: 61

( ! ) Fatal error: Call to a member function where() on a non-object in C:\wamp\www\ci_basic\application\libraries\SimpleLoginSecure.php on line 61
Call Stack
# Time Memory Function Location
1 0.0040 700048 {main}( ) ..\index.php:0
2 0.0064 793048 require_once( 'C:\wamp\www\ci_basic\system\core\CodeIgniter.php' ) ..\index.php:202
3 0.0412 2864760 call_user_func_array ( ) ..\CodeIgniter.php:359
4 0.0412 2864840 Signup->create_user( ) ..\CodeIgniter.php:359
5 0.0631 3190856 SimpleLoginSecure->create( ) ..\signup.php:23

I know i am missing something but cant seem to figure out what it is.

Can someone please point me in the right direction, i would really appreciate that.

Thanks
#2

[eluser]PhilTem[/eluser]
Please add your library's code. I guess we will find the error quickly and easily there. It's probably a missing assignment to the CI super-object.
#3

[eluser]seontist[/eluser]
The library code...
Code:
&lt;?php if (!defined('BASEPATH')) exit('No direct script access allowed');

require_once('phpass-0.3/PasswordHash.php');

define('PHPASS_HASH_STRENGTH', 8);
define('PHPASS_HASH_PORTABLE', false);

/**
* SimpleLoginSecure Class
*
* Makes authentication simple and secure.
*
* Simplelogin expects the following database setup. If you are not using
* this setup you may need to do some tweaking.
*  
*
*   CREATE TABLE `users` (
*     `user_id` int(10) unsigned NOT NULL auto_increment,
*     `user_email` varchar(255) NOT NULL default '',
*     `user_pass` varchar(60) NOT NULL default '',
*     `user_date` datetime NOT NULL default '0000-00-00 00:00:00' COMMENT 'Creation date',
*     `user_modified` datetime NOT NULL default '0000-00-00 00:00:00',
*     `user_last_login` datetime NULL default NULL,
*     PRIMARY KEY  (`user_id`),
*     UNIQUE KEY `user_email` (`user_email`),
*   ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
*
* @package   SimpleLoginSecure
* @version   2.0
* @author    Stéphane Bourzeix, Pixelmio <stephane[at]bourzeix.com>
* @copyright Copyright (c) 2012, Stéphane Bourzeix
* @license   http://www.gnu.org/licenses/gpl-3.0.txt
* @link      https://github.com/DaBourz/SimpleLoginSecure
*/
class SimpleLoginSecure
{
var $CI;
var $user_table = 'users';

/**
  * Create a user account
  *
  * @access public
  * @param string
  * @param string
  * @param bool
  * @return bool
  */
function create($user_email = '', $user_pass = '', $auto_login = true)
{
  $this->CI =& get_instance();
  


  //Make sure account info was sent
  if($user_email == '' OR $user_pass == '') {
   return false;
  }
  
  //Check against user table
  $this->CI->db->where('user_email', $user_email);
  $query = $this->CI->db->get_where($this->user_table);
  
  if ($query->num_rows() > 0) //user_email already exists
   return false;

  //Hash user_pass using phpass
  $hasher = new PasswordHash(PHPASS_HASH_STRENGTH, PHPASS_HASH_PORTABLE);
  $user_pass_hashed = $hasher->HashPassword($user_pass);

  //Insert account into the database
  $data = array(
     'user_email' => $user_email,
     'user_pass' => $user_pass_hashed,
     'user_date' => date('c'),
     'user_modified' => date('c'),
    );

  $this->CI->db->set($data);

  if(!$this->CI->db->insert($this->user_table)) //There was a problem!
   return false;      
    
  if($auto_login)
   $this->login($user_email, $user_pass);
  
  return true;
}

/**
  * Login and sets session variables
  *
  * @access public
  * @param string
  * @param string
  * @return bool
  */
function login($user_email = '', $user_pass = '')
{
  $this->CI =& get_instance();

  if($user_email == '' OR $user_pass == '')
   return false;


  //Check if already logged in
  if($this->CI->session->userdata('user_email') == $user_email)
   return true;
  
  
  //Check against user table
  $this->CI->db->where('user_email', $user_email);
  $query = $this->CI->db->get_where($this->user_table);

  
  if ($query->num_rows() > 0)
  {
   $user_data = $query->row_array();

   $hasher = new PasswordHash(PHPASS_HASH_STRENGTH, PHPASS_HASH_PORTABLE);

   if(!$hasher->CheckPassword($user_pass, $user_data['user_pass']))
    return false;

   //Destroy old session
   $this->CI->session->sess_destroy();
  
   //Create a fresh, brand new session
   $this->CI->session->sess_create();

   $this->CI->db->simple_query('UPDATE ' . $this->user_table  . ' SET user_last_login = NOW() WHERE user_id = ' . $user_data['user_id']);

   //Set session data
   unset($user_data['user_pass']);
   $user_data['user'] = $user_data['user_email']; // for compatibility with Simplelogin
   $user_data['logged_in'] = true;
   $this->CI->session->set_userdata($user_data);
  
   return true;
  }
  else
  {
   return false;
  }

}

/**
  * Logout user
  *
  * @access public
  * @return void
  */
function logout() {
  $this->CI =& get_instance();  

  $this->CI->session->sess_destroy();
}

/**
  * Delete user
  *
  * @access public
  * @param integer
  * @return bool
  */
function delete($user_id)
{
  $this->CI =& get_instance();
  
  if(!is_numeric($user_id))
   return false;  

  return $this->CI->db->delete($this->user_table, array('user_id' => $user_id));
}

}
?&gt;
#4

[eluser]Aken[/eluser]
Did you load the database?
#5

[eluser]seontist[/eluser]
Yes, i am all sorted thanks alot.
Much Appreciated




Theme © iAndrew 2016 - Forum software by © MyBB