You can just use mcrypt to encrypt/decrypt the passwords, but as Chad says, it should only be 1-way, so no-one can get your password.
$sql="select id from users where (username='$username', password='".md5($password)."')";
if you have a return, your user is ok.