<commit_before><?php

class Register extends CI_Controller
{
    function reg()
    {
        $this->load->helper('form');
        $this->load->library('form_validation');
        
        $rules = array(
            array('field' => 'fname',    'label' => 'Firstname',     'rules' => 'required'),
            array('field' => 'lname',    'label' => 'Lastname',      'rules' => 'required'),
            array('field' => 'mname',    'label' => 'Middlename',    'rules' => 'required'),
            array('field' => 'username', 'label' => 'Username',      'rules' => 'required'),
            array('field' => 'password', 'label' => 'Password',      'rules' => 'required')
        );

        $this->form_validation->set_rules($rules);

        if($this->form_validation->run() === FALSE)
        {
            $d['error'] = '';
            $this->load->view('user/register', $d);
        }
        else
        {
            $username = $this->input->post('username');
            $this->db->where('username', $username);
            $count = $this->db->count_all_results('users');
            if($count > 0)
            {
                $this->load->helper('string');

                $ar     = $this->db->get('users')->result_array();
                $data   = array();

                foreach($ar as $user)
                {
                    $data[] = $user['username'];
                }

                $suggest = increment_exists($username, $data);
                $d['error'] = '<div class="alert alert-danger text-center">
                        Username is already taken <br/>
                        Recommended username: '.$suggest.'</div>';
                $this->load->view('user/register', $d);
            }
            else
            {
                $password = $this->input->post('password');
                $con_pass = $this->input->post('con_pass');

                // TODO: check for a strong password

                if ($this->valid_pass($password)) {

                    if ($password == $con_pass) {
                        $config['upload_path']          = './assets/uploads/';
                        // check if the attachment belongs to image
                        $config['allowed_types']        = 'jpg|png|jpeg';
                        $config['max_size']             = 2048;
                        $config['encrypt_name']         = TRUE;
                        $this->load->library('upload', $config);

                        if ($this->upload->do_upload()) {
                            $data['pic']        = $this->upload->data('file_name');
                            $data['fname']      = ucwords($this->input->post('fname'));
                            $data['lname']      = ucwords($this->input->post('lname'));
                            $data['mname']      = ucwords($this->input->post('mname'));
                            $data['email']      = $this->input->post('email');
                            $data['bday']       = $this->input->post('bday');
                            $data['contact']    = $this->input->post('contact');
                            $data['username']   = $username;
                            $data['password']   = <PASSWORD>(<PASSWORD>);
                            $data['address']    = $this->input->post('address');
                            $data['gender']     = $this->input->post('gender');
                            $data['question']   = $this->input->post('secret_q');
                            $data['answer']     = $this->input->post('answer_q');
                            $this->db->insert('users', $data);
                            $this->session->set_flashdata('message', alert('Successfully registered', 'success'));
                            redirect('/register');
                        } else {
                            $d['error'] = alert($this->upload->display_errors());
                            $this->load->view('user/register', $d);
                        }
                        
                    } else {
                        $d['error'] = alert('Please confirm your password');
                        $this->load->view('user/register', $d);
                    }
                    
                } else {
                    $d['error'] = '<div class="alert alert-danger">Password must have at
                                    least one capital letter a small letter a number and special character</div>';
                    $this->load->view('user/register', $d);
                }
                
            }
        }
    }
    
    function valid_pass($candidate) 
    {
        $r1='/[A-Z]/';  //Uppercase
        $r2='/[a-z]/';  //lowercase
        $r3='/[!@#$%&*()^,._;:-]/';  // whatever you mean by 'special char'
        $r4='/[0-9]/';  //numbers
        
        if(preg_match_all($r1,$candidate, $o)<1) return FALSE;
        
        if(preg_match_all($r2,$candidate, $o)<1) return FALSE;
        
        if(preg_match_all($r3,$candidate, $o)<1) return FALSE;
        
        if(preg_match_all($r4,$candidate, $o)<1) return FALSE;
        
        return TRUE;
    }
}<commit_msg>password length atleast 8 characters<commit_after><?php

class Register extends CI_Controller
{
    function reg()
    {
        $this->load->helper('form');
        $this->load->library('form_validation');
        
        $rules = array(
            array('field' => 'fname',    'label' => 'Firstname',     'rules' => 'required'),
            array('field' => 'lname',    'label' => 'Lastname',      'rules' => 'required'),
            array('field' => 'mname',    'label' => 'Middlename',    'rules' => 'required'),
            array('field' => 'username', 'label' => 'Username',      'rules' => 'required'),
            array('field' => 'password', 'label' => 'Password',      'rules' => 'required')
        );

        $this->form_validation->set_rules($rules);

        if($this->form_validation->run() === FALSE)
        {
            $d['error'] = '';
            $this->load->view('user/register', $d);
        }
        else
        {
            $username = $this->input->post('username');
            $this->db->where('username', $username);
            $count = $this->db->count_all_results('users');
            if($count > 0)
            {
                $this->load->helper('string');

                $ar     = $this->db->get('users')->result_array();
                $data   = array();

                foreach($ar as $user)
                {
                    $data[] = $user['username'];
                }

                $suggest = increment_exists($username, $data);
                $d['error'] = '<div class="alert alert-danger text-center">
                        Username is already taken <br/>
                        Recommended username: '.$suggest.'</div>';
                $this->load->view('user/register', $d);
            }
            else
            {
                $password = $this->input->post('password');
                $con_pass = $this->input->post('con_pass');

                // TODO: check for a strong password

                if ($this->valid_pass($password)) {

                    if ($password == $con_pass) {
                        $config['upload_path']          = './assets/uploads/';
                        // check if the attachment belongs to image
                        $config['allowed_types']        = 'jpg|png|jpeg';
                        $config['max_size']             = 2048;
                        $config['encrypt_name']         = TRUE;
                        $this->load->library('upload', $config);

                        if ($this->upload->do_upload()) {
                            $data['pic']        = $this->upload->data('file_name');
                            $data['fname']      = ucwords($this->input->post('fname'));
                            $data['lname']      = ucwords($this->input->post('lname'));
                            $data['mname']      = ucwords($this->input->post('mname'));
                            $data['email']      = $this->input->post('email');
                            $data['bday']       = $this->input->post('bday');
                            $data['contact']    = $this->input->post('contact');
                            $data['username']   = $username;
                            $data['password']   = <PASSWORD>($password);
                            $data['address']    = $this->input->post('address');
                            $data['gender']     = $this->input->post('gender');
                            $data['question']   = $this->input->post('secret_q');
                            $data['answer']     = $this->input->post('answer_q');
                            $this->db->insert('users', $data);
                            $this->session->set_flashdata('message', alert('Successfully registered', 'success'));
                            redirect('/register');
                        } else {
                            $d['error'] = alert($this->upload->display_errors());
                            $this->load->view('user/register', $d);
                        }
                        
                    } else {
                        $d['error'] = alert('Please confirm your password');
                        $this->load->view('user/register', $d);
                    }
                    
                } else {
                    $d['error'] = '<div class="alert alert-danger">Password must have at
                                    least one capital letter a small letter a number and special character</div>';
                    $this->load->view('user/register', $d);
                }
                
            }
        }
    }
    
    function valid_pass($candidate) 
    {
        $r1='/[A-Z]/';  //Uppercase
        $r2='/[a-z]/';  //lowercase
        $r3='/[!@#$%&*()^,._;:-]/';  // whatever you mean by 'special char'
        $r4='/[0-9]/';  //numbers

        if (strlen($candidate) < 8) return FALSE;
        
        if (preg_match_all($r1,$candidate, $o)<1) return FALSE;
        
        if (preg_match_all($r2,$candidate, $o)<1) return FALSE;
        
        if (preg_match_all($r3,$candidate, $o)<1) return FALSE;
        
        if (preg_match_all($r4,$candidate, $o)<1) return FALSE;
        
        return TRUE;
    }
}
{'fraction_non_alphanumeric': 0.17165976302860997, 'fraction_numerical': 0.003853193333975532, 'mean_word_length': 1.2837659480862296, 'pattern_counts': {'":': 0, '<': 27, '<?xml version=': 0, '>': 180, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1348911', 'n_tokens_mistral': 2801, 'n_tokens_neox': 2654, 'n_words': 453}