I am currently making a change password area and I wish for users to be able to change it although for passwords to be more secure we ask that passwords contain both letters and numbers and if users so choose they may have special characters as well..

I could not find anything PHP based that would help me check the password they are trying to change it to actually contains both numbers and letters, and if it contains characters that it accepts these also, although it will not cause an error if they don't have special characters...

So I want to be able to check for numbers and letters without removing special characters if they have them. If they don't have special characters that is fine.. although if they do not have a number or letter in their new password it will error..

Any help would be much appreciated!

if (empty($password)) {
	echo "Password is empty";
} else if (!preg_match("#[a-z]#i",$password)) {
	echo "Password needs letters";
} else if (!preg_match("#[0-9]#i",$password)) {
	echo "Password needs numbers";
} else {
	echo "Password has both letters and numbers";
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.