xtremer360's Profile User Rating: -----

Reputation: -2 Dishonored
Group:
Active Members
Active Posts:
123 (0.09 per day)
Joined:
03-March 11
Profile Views:
1,232
Last Active:
User is offline Feb 11 2014 12:27 AM
Currently:
Offline

Previous Fields

Country:
US
OS Preference:
Windows
Favorite Browser:
FireFox
Favorite Processor:
Intel
Favorite Gaming Platform:
Playstation
Your Car:
Pontiac
Dream Kudos:
0
Icon   xtremer360 has not set their status

Posts I've Made

  1. In Topic: Shrinking Login submit function

    Posted 25 Jul 2013

    View PostMartyr2, on 25 July 2013 - 01:23 PM, said:

    Considering all the tasks you are doing here I think you have quite the bargain in the number of lines. If you cut out some of line wrapping you could save another 5 lines or so and make it appear a little sleeker, but I don't see anything terribly disturbing about your code there beyond the idea that maybe the submit is doing too many things.

    :)


    That's what I'm concerned about is the submit function actually performing too many things. What would be a recommendation you can give me that will help improve the function by making some smaller functions out of it. Would it be anymore helpful if I posted the controller which includes those other methods that are called inside of the submit method.
  2. In Topic: Where should I START learning PHP?

    Posted 22 Jul 2013

    I would also look into picking up one or two books on the topic and/or reading up on the language website at http://www.php.net for documentation.
  3. In Topic: Account Creation

    Posted 22 Jul 2013

    Have you commented out your code and ran any tests to see where the issue is coming from?
  4. In Topic: Flattened Code Has Some Recursion Issue

    Posted 4 Jun 2013

    I think after looking at it again I have figured it out.

    <?php
    
    if ( ! defined('BASEPATH')) exit('No direct script access allowed');
    
    class Login extends Backend_Controller
    {
    	public function __construct()
    	{
    		parent::__construct();
    		$this->load->model('users_model');
    	}
    
    	public function index()
    	{
    		Asset::js('theme::login.js');
    
    		$this->template
    		->title('KOW Manager Login')
    		->set_layout('usermanagement')
    		->build('login');
    	}
    
    	public function form_is_valid()
    	{
    		/* Set validation rules for post data */
    		$this->form_validation->set_rules('username', 'Username', 'trim|required|xss_clean|min_length[6]|max_length[12]|regex_match[/[a-z0-9]/]');
    		$this->form_validation->set_rules('password', 'Password', 'trim|required|xss_clean|min_length[6]|max_length[12]|regex_match[/[a-z0-9]/]');
    		//$this->form_validation->set_rules('remember', 'Remember Me', 'trim|xss_clean|integer');
    
    		/* Form validation passed */
    		return $this->form_validation->run();
    	}
    
    	public function is_user_locked($user_lock_date)
    	{
    		if (strtotime($user_lock_date) > 0)
    		{
    			/* User is locked out */
    
    			if (strtotime(gmdate('Y-m-d H:i:s', time())) < strtotime($user_lock_date))
    			{
    				/* User is still locked out */
    				return TRUE;
    			}
    			else
    			{
    				/* User can be unlocked and form be resubmitted */
    				$this->users_model->unlock_user($user_data->user_id);
    			
    				/* User is no longer locked out */
    				return FALSE;
    			}
    
    		}
    	}
    
    	public function check_user_status($user_status_id)
    	{
    		/* Match user status */
    		switch ($user_status_id)
    		{
    			case 1:
    				$this->output('Sorry you must verify your account before logging in!', 'Account Unverified', 'Error');
    				break;
    			case 3:
    				$this->output('Your account has been suspended!', 'Account Suspended', 'Error');
    				break;
    			case 4:
    				$this->output('Your account has been suspended!', 'Account Banned', 'Error');
    				break;
    			case 5:
    				$this->output('Your account has been deleted!', 'Account Deleted', 'Error');
    				break;
    			default:
    				return;
    		}
    	}
    
    	public function output($message, $title, $status)
    	{
    		switch (strtoupper($status))
    		{
    			default:
    			case 'ERROR':
    				$status = 'Error';
    				break;
    			case 'NOTICE':
    				$status = 'Notice';
    				break;
    			case 'SUCCESS':
    				$status = 'Success';
    				break;
    			}
    			$this->output
    			    ->set_content_type('application/json')
    			    ->set_output(json_encode(array('output_status' => $status, 'output_title' => $title, 'output_message' => $message)));
    	}
    
    	public function start_user_session()
    	{
    		/* Start session with user id and clear previous failed login attempts */
    		$this->session->set_userdata('uid', $user_data->user_id);
    		$this->session->unset_userdata('failed_logins');
    		$this->users_model->insert_session($user_data->user_id, gmdate('Y-m-d H:i:s', time()));
    		return;
    	}
    
    	public function submit()
    	{
    		if (!$this->form_is_valid())
    		{
    			$this->output('The form did not validate successfully!', 'Form Not Validated', 'Error');
    			return;
    		}
    
    		/* Post values from login form */
    		$post_username = $this->input->post('username');
    		$post_password = $this->input->post('password');
    
    		/* Test to see value of posted login form */
    		//echo '<pre>';
    		//var_dump($post_username);
    		//var_dump($post_password);
    		//echo '</pre>';
    		//die();
    
    		/* Get user data from post username value */
    		$user_data = $this->users_model->get_by('username', $post_username);
    
    		/* Test to see value of $user_data */
    		//echo '<pre>';
    		//var_dump($user_data);
    		//echo '</pre>';
    		//die();
    
    		if (count($user_data) == 0)
    		{
    			/* User was not found in database */
    			$this->output('The user was not found in the database!', 'User Not Found', 'Error');
    			return;
    		}
    
    		/* User was found in database */
    
    		if ($this->is_user_locked($user_data->lock_date))
    		{
    			/* User is locked from logging in from too many failed attempts */
    			$this->output('This user account is currently locked!', 'Account Locked', 'Error');
    			return;
    
    		/* User is unlocked from logging in */
    
    		if ($user_data->user_status_id != 2)
    		{
    			/* User has a status that is not allowed to proceed */
    			$this->user_status_message($user_data->user_status_id);
    		}
    
    		/* User is registered and validated */
    
    		$regenerated_post_password = $this->genfunc->reGenPassHash($post_password, $user_data->password_hash);
    
    		$failed_logins = $this->session->userdata('failed_logins');
    
    		if ($regenerated_post_password !== $user_data->password)
    		{
    			/* Password from login from does not match user stored password */
    
    			if ($failed_logins == 0)
    			{
    				/* First time user has not entered username and password successfully */
    				$this->session->set_userdata('failed_logins', 1);
    				$this->users_model->increase_login_attempt($this->input->ip_address(), $post_username, gmdate('Y-m-d H:i:s', time()));
    				$this->output('Incorrect username and password credentials!', 'Incorrect Login Credentials', 'Error');
    				return;
    			}
    
    			/* User has atleast one failed login attempt for the current session */
    
    			if ($failed_logins !== 4)
    			{
    				/* User has a few more chances to get password right */
    				$failed_logins++;
    				$this->session->set_userdata('failed_logins', $failed_logins);
    				$this->users_model->increase_login_attempt($this->input->ip_address(), $post_username, gmdate('Y-m-d H:i:s', time()));
    				$this->output('Incorrect username and password credentials!', 'Incorrect Login Credentials', 'Error');
    				return;
    			}
    
    			$this->users_model->lock_out_user($user_data->user_id, gmdate('Y-m-d H:i:s', time()+(60*15)));
    			//$this->functions_model->send_email('maximum_failed_login_attempts_exceeded', $user_data->email_address, $user_data)
    			$this->output('Your account is currently locked, we apologize for the inconvienence. You must wait 15 minutes before you can log in again! An email was sent to the owner of this account! Forgotten your username or password? <a href="forgotusername">Forgot Username</a> or <a href="forgotpassword">Forgot Password</a>', 'Account Locked', 'Error');
    			return;
    		}
    
    		/* Password from login form matches user stored password and user may login */
    
    		$this->output('Successful login! Sending you to the dashboard!', 'Login Sucessful', 'Success');
    		return;
    	}
    }
    
    
  5. In Topic: Flattened Code Has Some Recursion Issue

    Posted 4 Jun 2013

    I'm going to work on the first part but I wanted to ask you about the second. I have the default for the user_lock_date set as 0000-00-00 00:00:00 in the database. Which means if its that then the user is obviously not locked out. Is your suggestion still viable.


    public function is_user_locked($user_lock_date)
    	{
    		if (strtotime($user_lock_date) > 0)
    		{
    			/* User is locked out */
    
    			if (strtotime(gmdate('Y-m-d H:i:s', time())) < strtotime($user_lock_date))
    			{
    				/* User is still locked out */
    				return TRUE;
    			}
    			else
    			{
    				/* User is no longer locked out */
    				return FALSE;
    			}
    
    		}
    	}
    

My Information

Member Title:
D.I.C Head
Age:
29 years old
Birthday:
December 18, 1984
Gender:
Location:
Basehor, Kansas
Full Name:
Jeffrey Davidson
Programming Languages:
PHP, Javascript, MySQL, jQuery, Visual Basic

Contact Information

E-mail:
Private
AIM:
AIM  xtremer360
Website URL:
Website URL  http://www.jeffdavidson.me
Yahoo:
Yahoo  xtremer360
Skype:
Skype  jeff.davidson84
Facebook:
http://www.facebook.com/YankeeFanInKC
Twitter:
xtremer360

Friends

xtremer360 hasn't added any friends yet.

Comments

xtremer360 has no profile comments yet. Why not say hello?