Your question is not easily answered without knowing more information about the environment which it is to be used in.
Presumably the username and password are coming from some kind of database on your server or maybe even the authentication system that comes by default on your server platform?
Why not use a sesssion variable so that you know your user is logged in. You can then check for this variable on each page (using a server-side language such as ASP or PHP) and redirect the user to the login page accordingly.
If you can explain in a bit more detail what you are trying to do (and the language you are trying to do it in), I'm sure someone here will be able to explain things a bit further.
As easy as 3.1415926535897932384626433832795028841