If you are trying to make a custom login module in Magento then Magento have a default functionality to make a Custom login session,Which destroy automatically after some time, if you will be Inactive for a moment.

Here I am showing you How to set login session value and How to get login session value.

$sql='select * from `tablename` where `username`= "'.$username.'" and `password`="'.$password.'" ';
$read = Mage::getSingleton('core/resource')->getConnection('core_read');
$row = $read->fetchAll($sql);

Now You have Logged in to your account. If you want to retrieve login Session value then you need to write the following code

$login = Mage::getSingleton('core/session')->getlogin();