Jump to content

password validation


littlepeg

Recommended Posts

Hi everybody, would you please help me with this password validation problems. I want to check whether the password length is more than 6 characters, if not, shows error message. But I think there is something wrong with my codes, because it did not check whether the password is over 6 characters. Any help will be appreciated and grateful. Thank you.  :)

 

if (!empty($_POST['password1'])) {
	if ($_POST['password1'] != $_POST['password2']) {
		$errors[] = 'Your password did not match the confirmed password.';
	} else {
	  if (strlen($_POST['password1']<6) {
	    $errors[]='Your password must be at least 6 characters long.';}
		else{
		$p = $_POST['password1'];}
	}
} else {
	$errors[] = 'You forgot to enter your password.';
}

Link to comment
https://forums.phpfreaks.com/topic/53846-password-validation/
Share on other sites

Oh, yes. Thank you. You found a mistake for me. I changed it. However, it is still not working, still could not check 6 characters for the entered password.

if (!empty($_POST['password1'])) {
	if ($_POST['password1'] != $_POST['password2']) {
		$errors[] = 'Your password did not match the confirmed password.';
	} else {
	  [color=red]if (strlen($_POST['password1'])<6) [/color]{
	    $errors[]='Your password must be at least 6 characters long.';}
		else{
		$p = $_POST['password1'];}
	}
} else {
	$errors[] = 'You forgot to enter your password.';
}

Link to comment
https://forums.phpfreaks.com/topic/53846-password-validation/#findComment-266180
Share on other sites

This is how i would do it...

 

<?php
if (!empty(addslashes($_POST['password1']))){

/*
Security .. check for valid data
ctype_alnum checks for letters,numbers

*/
if (!ctype_alnum($_POST['password1'])){
$errors[] = 'Your password was invalid.';
}elseif (ctype_alnum($_POST['password1'])){

if ($_POST['password1'] != $_POST['password2']){
$errors[] = 'Your password did not match the confirmed password.';
}elseif ($_POST['password1'] == $_POST['password2']){

if (strlen($_POST['password1'])<6){
$errors[]='Your password must be at least 6 characters long.';
}elseif (strlen($_POST['password1'])>=6){
$p = $_POST['password1'];
}else{
$errors[] = 'You forgot to enter your password.';
}}}}
}
?>

Link to comment
https://forums.phpfreaks.com/topic/53846-password-validation/#findComment-266183
Share on other sites

<?php
if (isset($_POST['password1'])){

if (!ctype_alnum($_POST['password1'])){
echo "Your password was invalid.";
}elseif (ctype_alnum($_POST['password1'])){

if ($_POST['password1'] != $_POST['password2']){
echo "Your password did not match the confirmed password.";
}elseif ($_POST['password1'] == $_POST['password2']){

if (strlen($_POST['password1'])<6){
echo "Your password must be at least 6 characters long.";
}elseif (strlen($_POST['password1'])>=6){

$p = $_POST['password1'];

}else{
echo "You forgot to enter your password.";
}}}}
?>

 

This should work..

Link to comment
https://forums.phpfreaks.com/topic/53846-password-validation/#findComment-266230
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.