stelthius Posted December 14, 2008 Share Posted December 14, 2008 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 https://forums.phpfreaks.com/topic/136891-solved-varifying-passwrods-both-match/ Share on other sites More sharing options...
stelthius Posted December 14, 2008 Author Share Posted December 14, 2008 what i forgot to mention is that it isnt checking both passwords are the same am i missing something ? Rick Link to comment https://forums.phpfreaks.com/topic/136891-solved-varifying-passwrods-both-match/#findComment-714952 Share on other sites More sharing options...
stelthius Posted December 14, 2008 Author Share Posted December 14, 2008 Is there an easier way to do this without even editing my main PHP files, ? Link to comment https://forums.phpfreaks.com/topic/136891-solved-varifying-passwrods-both-match/#findComment-714958 Share on other sites More sharing options...
dropfaith Posted December 14, 2008 Share Posted December 14, 2008 js <script language="javascript"> document.forms[0].onsubmit = function() { if(this.elements['password'].value != this.elements['password_confirm'].value) { alert('Passwords do not match'); return false; } return true; } </script> Link to comment https://forums.phpfreaks.com/topic/136891-solved-varifying-passwrods-both-match/#findComment-714959 Share on other sites More sharing options...
stelthius Posted December 14, 2008 Author Share Posted December 14, 2008 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 https://forums.phpfreaks.com/topic/136891-solved-varifying-passwrods-both-match/#findComment-714961 Share on other sites More sharing options...
stelthius Posted December 14, 2008 Author Share Posted December 14, 2008 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 https://forums.phpfreaks.com/topic/136891-solved-varifying-passwrods-both-match/#findComment-714977 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.