RalphLeMouf Posted September 18, 2012 Share Posted September 18, 2012 Hello - I am putting the finishing touches on my form that creates users for my website. After much research and trying different things, I am having great trouble getting the password field to post an error, although the confirm password field is just fine. I have been stuck on this for way to long any help is greatly appreciated. Here is my code: VIEW: echo form_label('', 'email', array('type'=>'text')); $data = array( 'name' => 'first_name', 'class' => 'input', 'placeholder' => 'First Name' ); echo form_input($data, set_value('first_name')); echo "<div class='errors'>"; echo form_error('first_name'); echo "</div>"; echo form_label('', 'last_name', array('type'=>'text')); $data = array( 'name' => 'last_name', 'class' => 'input', 'placeholder' => 'Last Name' ); echo form_input($data, set_value('last_name')); echo "<div class='errors'>"; echo form_error('last_name'); echo "</div>"; echo form_label('', 'email', array('type'=>'text')); $data = array( 'name' => 'email', 'class' => 'input', 'placeholder' => 'Email' ); echo form_input($data, set_value('email')); echo "<div class='errors'>"; echo form_error('email'); echo "</div>"; echo form_label('', 'password', array('type'=>'password')); $data = array( 'name' => 'password', 'class' => 'password', 'size' => 30, 'placeholder' => 'Password' ); echo form_password($data, set_value('sha1(password)')); echo "<div class='errors'>"; echo form_error('password'); echo "</div>"; echo form_label('', 'password2', array('type'=>'password')); $data = array( 'name' => 'password2', 'class' => 'input', 'size' => 30, 'placeholder' => 'Confirm Password' ); echo form_password($data, set_value('sha1(password2)')); echo "<div class='errors'>"; echo form_error('password2'); echo "</div>"; MODEL: function create_member() { $salt = $this->_salt(); $this->load->library('encrypt'); $new_member_insert_data = array( 'first_name' => $this->input->post('first_name'), 'last_name' => $this->input->post('last_name'), 'email' => $this->input->post('email'), 'password' => $this->encrypt->sha1($salt . $this->encrypt->sha1($this->input->post('password'))), 'salt' => $salt, 'status' => 'pending' ); $insert = $this->db->insert('users', $new_member_insert_data); return $insert; } thaks so much in advance Quote Link to comment https://forums.phpfreaks.com/topic/268519-how-do-i-make-the-password-field-properly-display-error-in-form-validation/ Share on other sites More sharing options...
Mahngiel Posted September 18, 2012 Share Posted September 18, 2012 where are your validation rules? Quote Link to comment https://forums.phpfreaks.com/topic/268519-how-do-i-make-the-password-field-properly-display-error-in-form-validation/#findComment-1378978 Share on other sites More sharing options...
RalphLeMouf Posted September 18, 2012 Author Share Posted September 18, 2012 forgot that sorry... $this->load->library('form_validation'); $this->form_validation->set_rules('first_name', 'First Name', 'trim|required'); $this->form_validation->set_rules('last_name', 'Last Name', 'trim|required'); $this->form_validation->set_rules('email', 'Email', 'trim|required|valid_email'); $this->form_validation->set_rules(sha1('password', 'trim|required|max_length[32]')); $this->form_validation->set_rules('password2', 'Confirm Password', 'trim|required|matches[password]'); Quote Link to comment https://forums.phpfreaks.com/topic/268519-how-do-i-make-the-password-field-properly-display-error-in-form-validation/#findComment-1378979 Share on other sites More sharing options...
Jessica Posted September 18, 2012 Share Posted September 18, 2012 What is it not doing? In what case does the password field not display an error? Also, there's no reason to limit the password to 32 characters. That's only making your site LESS secure. *jesirose waits for the response that makes it obvious OP is not hashing/salting passwords. Quote Link to comment https://forums.phpfreaks.com/topic/268519-how-do-i-make-the-password-field-properly-display-error-in-form-validation/#findComment-1378981 Share on other sites More sharing options...
RalphLeMouf Posted September 18, 2012 Author Share Posted September 18, 2012 when I submit the form without filling out the fields correctly, i.e. - if I hit submit with nothing filled out, all of the errors display " the email field is required" EXCEPT the password field does NOT post any error at all. What length should I make the password field? thanks Quote Link to comment https://forums.phpfreaks.com/topic/268519-how-do-i-make-the-password-field-properly-display-error-in-form-validation/#findComment-1378985 Share on other sites More sharing options...
Jessica Posted September 18, 2012 Share Posted September 18, 2012 So you're saying the first name field also displays the email is required? Don't limit password length at all. Quote Link to comment https://forums.phpfreaks.com/topic/268519-how-do-i-make-the-password-field-properly-display-error-in-form-validation/#findComment-1378987 Share on other sites More sharing options...
RalphLeMouf Posted September 18, 2012 Author Share Posted September 18, 2012 No, I am saying ALL of the field erros are correct and displaying what they should EXCEPT the password field. It is not yielding ANY message at all. Quote Link to comment https://forums.phpfreaks.com/topic/268519-how-do-i-make-the-password-field-properly-display-error-in-form-validation/#findComment-1378988 Share on other sites More sharing options...
Jessica Posted September 18, 2012 Share Posted September 18, 2012 I just noticed you have sha1 around that whole thing. $this->form_validation->set_rules(); What you're effectively doing here is this: $rule = sha1('password', 'trim|required|max_length[32]'); $this->form_validation->set_rules($rule); This should have triggered an error because those arguments won't work for sha1. You're basically giving set_rules an encrypted string. Quote Link to comment https://forums.phpfreaks.com/topic/268519-how-do-i-make-the-password-field-properly-display-error-in-form-validation/#findComment-1378991 Share on other sites More sharing options...
RalphLeMouf Posted September 18, 2012 Author Share Posted September 18, 2012 I guess I don't understand what your suggesting as I tried $rule = sha1('password', 'trim|required|max_length[32]'); $this->form_validation->set_rules($rule); as a replacement for what I had ( getting rid of max length 32) and it's still not displaying the error Quote Link to comment https://forums.phpfreaks.com/topic/268519-how-do-i-make-the-password-field-properly-display-error-in-form-validation/#findComment-1378995 Share on other sites More sharing options...
Mahngiel Posted September 18, 2012 Share Posted September 18, 2012 she's telling you that your hashing your rules so they cannot even be read lol. You need to learn how to use callback functions. You're not validating the names nor email is unique. Quote Link to comment https://forums.phpfreaks.com/topic/268519-how-do-i-make-the-password-field-properly-display-error-in-form-validation/#findComment-1378996 Share on other sites More sharing options...
RalphLeMouf Posted September 18, 2012 Author Share Posted September 18, 2012 thank you for putting me in the right direction. I got it to work! This is what I have to make sure I'm doing it in the most optimized manner: $this->load->library('form_validation'); $this->form_validation->set_rules('first_name', 'First Name', 'trim|required'); $this->form_validation->set_rules('last_name', 'Last Name', 'trim|required'); $this->form_validation->set_rules('email', 'Email', 'trim|required|valid_email|is_unique[users.email]'); $this->form_validation->set_rules('password', 'Password', 'trim|required'); $this->form_validation->set_rules('password2', 'Confirm Password', 'trim|required|matches[password]'); Quote Link to comment https://forums.phpfreaks.com/topic/268519-how-do-i-make-the-password-field-properly-display-error-in-form-validation/#findComment-1379009 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.