Jump to content

How do I make the password field properly display error in form validation?


RalphLeMouf

Recommended Posts

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

 

Link to comment
Share on other sites

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]');

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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]');

 

 

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.