Created
November 3, 2011 16:38
-
-
Save nolochemical/1336990 to your computer and use it in GitHub Desktop.
Quick cpanel login
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$this->library->load(array('form_validation','session', 'file', [url/uri])); | |
/* | |
You will need url helper for redirect. | |
check http://codeigniter.com/user_guide/helpers/url_helper.html | |
Here is a more complete contruct for this app, to continue forward.: | |
function __construct() | |
{ | |
parent::__construct(); | |
//$this->output->enable_profiler(TRUE); | |
$this->load->library( | |
array( | |
'session', | |
'form_validation', | |
'email', | |
'uri', | |
) | |
); | |
$this->load->helper( | |
array( | |
'url', | |
'file', | |
'string' | |
) | |
); | |
$this->form_validation->set_error_delimiters('<div class="error">', '</div>'); | |
} | |
*/ | |
function login() | |
{ | |
$this->form_validation->set_rules('username','username','trim|required'); | |
$this->form_validation->set_rules('password','password','trim|required|callback__admin_read_storage_nox'); | |
if($this->form_validation->run() == TRUE) | |
{ | |
# create a login session | |
$this->session->set_userdata('username',$this->input->post('username')); | |
redirect(site_url()); | |
} | |
else | |
{ | |
$this->load->view('login'); | |
} | |
} | |
function _admin_read_storage_nox() | |
{ | |
$this->form_validation->set_message('_admin_read_storage_nox', 'Invalid login, please try again.'); | |
if( get_filenames('./assets/data/') ) | |
{ | |
$s = get_filenames('./assets/data/', true); | |
foreach( $s as $adm ) | |
{ | |
$ext = strtolower(substr(strrchr($adm, '.'), 1)); | |
if( $ext == 'nox') | |
{ | |
$str = read_file($adm); | |
$creds = json_decode($str); | |
if( $creds->{'username'} == $this->input->post('username') && $creds->{'password'} == hash('sha256', strtolower($this->input->post('password'))) ) | |
{ | |
$this->session->set_userdata('user',json_encode(array('username'=>$creds->{'username'},'email'=>$creds->{'email'}))); | |
redirect('/welcome/panel'); | |
} | |
} | |
} | |
return FALSE; | |
} | |
} | |
Auth File | |
========= | |
assets/data/auth_file.nox (json) | |
{"username":"admin","email":"[email protected]","password":"ac9689e2272427085e35b9d3e3e8bed88cb3434828b43b86fc0596cad4c6e270"} //sha256('admin1234') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment