Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- require_once(APPPATH . 'controllers/admin/authcontroller.php');
- class Change_pass extends AuthController{
- function index(){
- $data['title'] = 'Change Password';
- $change_form_rules = array
- (
- 'password' => 'required|callback_check_password',
- 'captcha' => 'required|callback_check_captcha',
- 'new_pass' => 'required'
- );
- $change_form_fields = array
- (
- 'password' => ' Password ',
- 'captcha' => ' Captcha ',
- 'new_pass' => ' New Password '
- );
- $this->validation->set_message('required','Field %s harus diisi!');
- $this->validation->set_fields($change_form_fields);
- $this->validation->set_rules($change_form_rules);
- if ($this->validation->run() == FALSE)
- {
- $expiration = time()-300; // Two hour limit
- $this->db->query("DELETE FROM captcha WHERE captcha_time < ".$expiration);
- $vals = array(
- //'word' => 'Random word',
- 'word_length' => 6,
- 'img_path' => './uploads/',
- 'img_url' => base_url().'uploads/',
- 'font_path' => base_url().'system/fonts/Jester.ttf',
- 'img_width' => '150',
- 'img_height' => '50',
- 'expiration' => '3600'
- );
- $cap = create_captcha($vals);
- //
- $data['image']= $cap['image'];
- //mette nel db
- $dati = array(
- 'captcha_id' => '',
- 'captcha_time' => $cap['time'],
- 'ip_address' => $this->input->ip_address(),
- 'word' => $cap['word']
- );
- $query = $this->db->insert_string('captcha', $dati);
- $this->db->query($query);
- if(getField('Position') == 'Superadmin')
- $this->layout->display_admin('',$data,'change_pass');
- else
- $this->layout->display('',$data,'change_pass');
- }
- else
- {
- $name = getField('username');
- $data ['password'] = $this->input->post('new_pass');
- $new = dohash($this->input->post('new_pass'));
- $this->changepass_model->change_password($new,$name);
- if(getField('Position') == 'Superadmin')
- $this->layout->display_admin('',$data,'sukses_change');
- else
- $this->layout->display('',$data,'sukses_change');
- }
- }
- function check_captcha()
- {
- $captcha = $this->input->post('captcha');
- $expiration = time()-3600;
- // Then see if a captcha exists:
- $sql = "SELECT COUNT(*) AS count FROM captcha WHERE word = ? AND ip_address = ? AND captcha_time > ?";
- $binds = array($captcha, $this->input->ip_address(), $expiration);
- $query = $this->db->query($sql, $binds);
- $row = $query->row();
- if ($row->count == 0) {
- $this->validation->set_message('check_captcha', 'Captcha salah !');
- return FALSE;
- } else {
- return TRUE;
- }
- }
- function check_password($password){
- $username = getField('username');
- $pass = dohash($password);
- if($this->changepass_model->cek_password($pass,$username)){
- return TRUE;
- }
- else{
- $this->validation->set_message('check_password', 'Password salah');
- return False;
- }
- }
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement