PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
New to encryption. Well, new to most php, but expecially encryption.
Can't figure out why this doesn't work. The users password is stored in a mysql database (encrypted). When they login I want to compare that value to the value they entered.
<?php
$query = sprintf('SELECT * FROM users WHERE username = ''%s'' and password = ''%s''', $_POST['username'], crypt($_POST['password']));
$result = mysql_query($query, $link)
or die('DB-Error: '.mysql_error());
$num_rows = mysql_num_rows($result);
if ($num_rows == 0) { // No such username/password pair in DB
die('Username/Password mismatch!');
} else if ($num_rows > 1) { // More than 1 username/password matches - should not happen..
die('Database inconsistency!');
}
// Otherwise there is exactly 1 row matching the given username/password
$data = mysql_fetch_assoc($result);
echo 'Login successful';
print_r($data);
?>