Welcome Guest, Not a member yet? Register   Sign In
my own user registeration and login library!
#1

[eluser]A.M.F[/eluser]
hi people,

i finished to work on my members application, and i want u to see it and see if i can improve it some how, and offcourse u can use it if u need to.

this is how i built it:
i have a Forms.php controller, that containes the login() and the register() pages, as well as a securityimg() function (to validate the forms) and emailcheck() and usercheck() functions to see that the user name and email are not allready in the DB.

Forms.php

Code:
class Forms extends Controller
{
    function Forms()
    {
        parent::Controller();
        $this->load->model('user_m');
    }

    function index()
    {
        redirect('index.php');
    }


    function securityimg()
    {
        $this->load->library('securityimg_lib');

        // get parameters
        isset($_GET['width']) ? $iWidth = (int)$_GET['width'] : $iWidth = 150;
        isset($_GET['height']) ? $iHeight = (int)$_GET['height'] : $iHeight = 30;
  
        // create new image
        $this->securityimg_lib->SecurityImage($iWidth, $iHeight);

        $this->securityimg_lib->Create();
    }
    

    //
    //Handling with the Login
    //
    function login()
    {    
        $this->load->library('validation');

        $rules['username'] = "trim|required|alpha_dash|min_length[2]|max_length[32]|prep_for_form|htmlspecialchars|xss_clean";        
        $rules['password'] = "trim|required|min_length[4]|max_length[32]|prep_for_form|htmlspecialchars|xss_clean";
        $rules['remember'] = "prep_for_form|htmlspecialchars|xss_clean";

        $this->validation->set_rules($rules);
        $this->validation->set_error_delimiters('<b>שגיאה: </b>', '<br />');

        $fields['username']  = 'השם משתמש';
        $fields['password']  = 'הסיסמא';
        $fields['remember']  = 'זכור אותי';

        $this->validation->set_fields($fields);


        if ($this->validation->run() == FALSE)
        {
            $data['message'] = $this->validation->error_string;

            //security code is wrong?
            if ((isset($_POST['send'])) && ($this->session->userdata('code') != strtoupper($_POST['securityimg'])))
            {
                $data['message'] .= "<b>שגיאה: </b>הקוד אבטחה שגוי.";
            }

            $this->layout->buildPage('login', $data);
        }

        else //all the form fields are fine
        {
            //security code is wrong?
            if ($this->session->userdata('code') != strtoupper($_POST['securityimg']))
            {
                $data['message'] = "<b>שגיאה: </b>הקוד אבטחה שגוי.";
                $this->layout->buildPage('login', $data);
            }

            else
            {
                $pass = md5(sha1($_POST['password'])); //encrypting the password

                if ($this->user_lib->login($_POST['username'], $pass)) //checking the user data
                {

                    if ((isset($_POST['remember'])) && ($_POST['remember'] == "1")) //creating coockies
                    {
                        set_cookie('user', $pass, 3600*24*365);
                        set_cookie('name', $_POST['username'], 3600*24*365);
                    }
                    else //creating short time coockies
                    {
                        $this->session->set_userdata('user', $pass);
                        $this->session->set_userdata('name', $_POST['username']);
                    }

                    redirect('index.php');
                }

                else //username or password incorrect
                {
                    $data['message'] = "<b>שגיאה: </b>שם המשתמש או הסיסמא שהכנסת אינם נכונים.";
                    $this->layout->buildPage('login', $data);

                    //show_error('An unexpected error occurred, please try again.');
                }
            }
            
        }
    }

(ran out of characters)


Messages In This Thread
my own user registeration and login library! - by El Forum - 12-09-2007, 07:11 AM
my own user registeration and login library! - by El Forum - 12-09-2007, 07:12 AM
my own user registeration and login library! - by El Forum - 12-09-2007, 07:14 AM
my own user registeration and login library! - by El Forum - 01-11-2008, 12:16 AM
my own user registeration and login library! - by El Forum - 01-11-2008, 03:01 AM



Theme © iAndrew 2016 - Forum software by © MyBB