Theres a simple, two part answer to this question.
The first part: Don't store username/password in cookies, instead store a simple session identifier. This session identifier should be a randomly created string of probably at least 10 characters so it's impossible for a person with a session to guess the identifier to some one elses session.
Digest::MD5::md5_hex plus
rand,
$$ and
time should probably suffice.
What the session idenfitier allows you is to store all of the "sensitive" data someplace on the server so the user accessing your website can't edit it or even see it.
The second part is to use
crypt (or md5, or any other one way hashing function) to store hashed version of your passwords on the server. Then you take the plain text password submitted by the user, hash it, and compare it to the hashed version you have on disk. If it matches, the password is correct. The advantage to one way hashing functions, such as
crypt is that theres no (known) way to get the plain text back from the hash, so even if other users can read the password file it won't do them any good. (This is how the /etc/passwd file basically works on linux installations (ignoring shadow passwords))
These two suggestions, combined, will probably give you just about the most security you can reasonably expect from using a "public" server you don't have full control over.