Link to home
Start Free TrialLog in
Avatar of genesisvh
genesisvh

asked on

How to make sure username and password is case sensitive.

I have a validation php script that checks the registration form. I want it to make sure it checks the username and password is case sensitive.
//validate fields
	if(!$_POST["username"] || !$_POST["email"] || !$_POST["password1"] || !$_POST["password2"]){
		echo "<p>&nbsp;</p><p>&nbsp;</p><p>&nbsp;</p><br />Please fill the required fields, <p>&nbsp;</p><p>&nbsp;</p><a href='register.php'>Go to register page</a>";
	
	//validate password
	}else if($_POST["password1"] != $_POST["password2"]){
		echo "<p>&nbsp;</p><p>&nbsp;</p><p>&nbsp;</p><br />Please go back, PASSWORDS do not match! <p>&nbsp;</p><p>&nbsp;</p><a href='register.php'>Go to register page</a>";
	
	//validate password length
	}else if(strlen($_POST["password1"]) < 6){
		echo "<p>&nbsp;</p><p>&nbsp;</p><p>&nbsp;</p><br />Please go back, PASSWORD is too short! <p>&nbsp;</p><p>&nbsp;</p><a href='register.php'>Go to register page</a>";	
		
	//validate username length
	}else if(strlen($_POST["username"]) < 5){
		echo "<p>&nbsp;</p><p>&nbsp;</p><p>&nbsp;</p><br />Please go back, USERNAME is too short! MUST BE BETWEEN 5 to 10 characters.<p>&nbsp;</p><p>&nbsp;</p><a href='register.php'>Go to register page</a>";	
		
	//validate email	
	}else if(!(eregi("^.+@.+\\..+$", $_POST['email']))){	
		echo "<p>&nbsp;</p><p>&nbsp;</p><p>&nbsp;</p><br />Please enter a valid EMAIL! <a href='register.php'><p>&nbsp;</p><p>&nbsp;</p>Go to register page</a>";
	
	//validate captcha
	}else if(($_SESSION['security_code'] != $_POST['security_code']) || (empty($_SESSION['security_code'])) ){
		echo "<p>&nbsp;</p><p>&nbsp;</p><p>&nbsp;</p><br />CAPTCHA CODE does not match! <p>&nbsp;</p><p>&nbsp;</p><a href='register.php'>Go to register page</a>";
	
	}else{
		$conn=  mysql_connect($servername,$username,$password)or die(mysql_error());
		mysql_select_db("",$conn);
		
		// check if already registered
		$sql_check = "SELECT * FROM users WHERE email = '".$_POST[email]."'";
		$result_check = mysql_query($sql_check,$conn) or die(mysql_error());		
		$row = mysql_fetch_assoc($result_check);
		if($row['id']){
			echo "<p>&nbsp;</p><p>&nbsp;</p><p>&nbsp;</p><br />EMAIL already registered! <p>&nbsp;</p><p>&nbsp;</p><a href='register.php'>Go to register page</a>";

Open in new window

Avatar of Lukasz Chmielewski
Lukasz Chmielewski
Flag of Poland image

If you calculate hash value (like md5 or sha1) for the password and store it in the database like this, it IS case sensitive, md5("somepassword") <> md5(Somepassword). If this is what you mean... Or you want to check if there are big and small letters ?
your code already case sensitive i think, though i think usually password is case sensitive but username is case insensitive. in case you want to make it case insensitive, use function strtoupper to compare them.
ASKER CERTIFIED SOLUTION
Avatar of Brad Brett
Brad Brett
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
If you are just looking to make sure they cased it the same in a password box and a confirm password box you can use strcmp()

http://www.php.net/manual/en/function.strcmp.php
Avatar of genesisvh
genesisvh

ASKER

Yup You got it