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
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

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.