Click to See Complete Forum and Search --> : Case sensitive login


moondance
08-18-2003, 04:23 AM
If i've got a simple form with username and login, how can i make them case sensitive - so the password needs to match EXACTLY the password in the db? Is it with the ereg function?

pyro
08-18-2003, 07:21 AM
Yes, you could use regexp, but an if statement is also case sensative:

<?PHP
$pass = "PyRo";
if ($pass == "pyro") {
echo "Try one successful<br>";
}
else {
echo "Try one not successful<br>";
}
if ($pass == "Pyro") {
echo "Try two successful<br>";
}
else {
echo "Try two not successful<br>";
}
if ($pass == "PyRo") {
echo "Try three successful<br>";
}
else {
echo "Try three not successful<br>";
}
?>

moondance
08-18-2003, 09:23 AM
so then how can i use the ereg function when i'm using something like:

mysql_query("select * from ccf_customer where customerid='$Name'and custpassword='$Password'");

to verify a user from the db?

pyro
08-18-2003, 09:30 AM
I would use preg_match, something like this:

<?PHP
$pass = "PyRo";
if (preg_match("/^PyRo$/",$pass)) {
echo "The passwords matched.";
}
else {
echo "The passwords did not match.";
}
?>

brendandonhue
08-18-2003, 09:41 AM
If your storing passwords in the database, you should probably hash them with MD5 (or another hashing method) for security purposes. MD5 itself is case sensitive, so you could just use an if statement.

moondance
08-18-2003, 10:35 AM
Just found a much simpler way:

In mySQL (phpMyAdmin), set the attribute of, say, the password, to Binary. This creates a case-sensitive field.

:D