Jump to content

Password length validation


Nodral

Recommended Posts

Hi

 

I've written a bit of code to validate whether a user has typed into a password box by using

if(strlen($password>0)){ // ok to save password. 
}else{ //give error message
}

However this is constntly saying the password is blank.  Any ideas?

 

My actual code follows below.  I know that the $password variable is set as I've echoed it out as a test.

 

<?php if(isset($_POST['pconf'])){
		//has a password been entered?
		echo $password;
			if(strlen($password >0)){
				//do new passwords match?
				if($pword===$password){
					//encode pword
					$pword=md5($pword);
					//write to DB
					$sql="UPDATE pfp_user SET firstname = '$firstname', password = '$password', lastname = '$lastname', email = '$email', dept = '$dept', workplace = '$workplace' , home = '$home', complete = 'yes'  WHERE id = " . $_SESSION['USERID'];
					mysql_query($sql) or die("<b>A fatal MySQL error occured</b>.\n<br />Query: " . $sql . "<br />\nError: (" . mysql_errno() . ") " . mysql_error());
					//redirect back to menu page
					$_SESSION['output']='Your user profile has been successfully updated';
					$extra="menu.php";
					header("Location: http://$host$uri/$extra");
				}else{
					$_SESSION['warning']="Please re-enter your passwords as they do not match";
					$_POST['pass']="";
				}
			}else{
				$_SESSION['warning']="You cannot have a blank password<br>Please re-enter.";
				$_POST['pass']="";
			}
	}else{
		$sql="UPDATE pfp_user SET firstname = '$firstname', lastname = '$lastname', email = '$email', dept = '$dept', workplace = '$workplace' , home = '$home', complete = 'yes'  WHERE id = " . $_SESSION['USERID'];
		mysql_query($sql) or die("<b>A fatal MySQL error occured</b>.\n<br />Query: " . $sql . "<br />\nError: (" . mysql_errno() . ") " . mysql_error());
		//redirect back to menu page
		$_SESSION['output']='Your user profile has been successfully updated';
		$extra="menu.php";
		header("Location: http://$host$uri/$extra");}?>

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

$password comes from a form and I know it has value as I've echoed it out in the top of the code I posted, as a test.

 

I didn't think you'd appreciate 200 lines of code being posted, so I just posted the relevant parts.

 

It's not writing to the DB which indicates that the if(strlen() function has an error

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.