Jump to content

[SOLVED] Varifying passwrods both match


stelthius

Recommended Posts

Hey guys, im just  messing with a login form and im trying to add a second field for confirming the pass is correct, ive done everything correct but it seems that this one is letting me down,

 

 

This is the code for the first original password field

 

      $field = "pass";  //Use field name for password
      if(!$subpass){
         $form->setError($field, "* Password not entered");
      }
      else{
         $subpass = stripslashes($subpass);
         if(strlen($subpass) < 4){
            $form->setError($field, "* Password too short");
         }
         else if(!eregi("^([0-9a-z])+$", ($subpass = trim($subpass)))){
            $form->setError($field, "* Password not alphanumeric");
         }      

 

This works fine but im trying to add a second field for checking that they have entered the same password twice  so i used this for pass2

 

 

/* pass2 error checking */
$field = "pass2"; //Use field name for pass2word
if(!$subpass2){
$form->setError($field, "* password not entered");
}
else{
$subpass2 = stripslashes($subpass2);
if(strlen($subpass2) < 4){
$form->setError($field, "* password too short");
}
else if(!eregi("^([0-9a-z])+$", ($subpass2 = trim($subpass2)))){
$form->setError($field, "* password not alphanumeric");
} 
}

 

i thought this would have worked, well it is working its adding the passwords to the DB but i can register with abcdefg and aaaaaa and still be able to register any help would be great :)

 

Rick

Link to comment
Share on other sites

Thanks for replying Drop, i dont actually use js all that much so this is gonna seem like a stupid question but i assume i need to add a value to my password fields so the JS can check they are both the same, what would it be from the snippet you just replied with ?

 

Regards Rick

Link to comment
Share on other sites

I solved this by changing this

 

 

/* pass2 error checking */
$field = "pass2"; //Use field name for pass2word
if(!$subpass2){
$form->setError($field, "* password not entered");
}
else{
$subpass2 = stripslashes($subpass2);
if(strlen($subpass2) < 4){
$form->setError($field, "* password too short");
}
else if(!eregi("^([0-9a-z])+$", ($subpass2 = trim($subpass2)))){
$form->setError($field, "* password not alphanumeric");
} 
}

 

to this

 

/* Password2 error checking */
$field = "pass"; //Use field name for password
$field2 = "pass2"; // Second field for password
if(!$subpass2){
$form->setError($field2, "* Password not entered");
}
else{
//$subpass = stripslashes($subpass);
//$subpass2 = stripslashes($subpass2);
if($subpass!==$subpass2){
$form->setError($field2, "* Passwords does not match");
} 
}

 

Rick

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.