Jump to content
  • Advertisement
Sign in to follow this  
TheBlackVegetable

Password Encryption

This topic is 4236 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi and welcome to a newbie's attempts at cryptography. I have a client-server application, where the user logs in with a username and password. I want to encrypt that password before sending it to the server. So far I've got a system where the server sends an encrypted message to the client every time the client logs in, that contains a regularly changed passphrase. The client decrypts the message and uses the passphrase to encrypt the password. However, the master phrase used to encrypt the passphrase is stored in a static const std::string on both the server and client (so the client has a way of decrypting the passphrase sent to it). I have a feeling that this is a Bad Idea, as a hacker could get the master phrase, but this is my very first attempt at cryptography, and I'm not sure exactly what kinds of things I should be searching for to find out how to properly tackle my problem. I'm sure this is a solved problem, so my question is, does anyone know a website or book that I can use as a starting point?

Share this post


Link to post
Share on other sites
Advertisement
You could just do a one-way hash of the password, using an algorithm such as the SHA algorithm. The server could send the client some random data (such as the time or a random string) and the client combines the data from the server and the password and sends the hash of that to the server. The server does the same thing with its copy of the password and the data it sent and if the two match, the client is authenticated.

Because a good hash function is one way, anyone listening in can't get the password from the hash, and because the server sends different "salt" data to be combined with the hash every time, you can't just send the same data as the last time someone logged in.

You can google for C source code for SHA hashing. Be sure to use SHA 256 or better or another secure hash function; older versions of SHA are less secure.

If you want to be really secure, you could also use public key cryptography, such as the RSA algorithm, to encrypt the data before sending it to the server. I think that might be overkill, though.

Share this post


Link to post
Share on other sites
nagromo's proposal is almost good, except for the fact that the server stores a plaintext password ("The server does the same thing with its copy of the password"). That's usually a bad idea. Apart from that, sending hashes of passwords and random data over the network is what many successful real-life algorithms do.

Generally, it is a bad idea to try and implement a security scheme on one's own. Although a few people may actually be lucky and get it right, almost everybody will have a fundamental flaw hidden somewhere in his implementation.
Using an existing scheme that has proven its value in the field is often better. I suggest reading Bruce Schneier's books. They contain known implementations of all kind of authentification/encryption/signature/whatever algorithms along with their analysis, problems, etc.

Share this post


Link to post
Share on other sites
Quote:
Original post by Damon Shamkite
nagromo's proposal is almost good, except for the fact that the server stores a plaintext password ("The server does the same thing with its copy of the password"). That's usually a bad idea.

Thats true! But you could do a double hashing. First, hash the password with a fixed function A and store this hash on your server. If you now want to login in, you will hash the users password with A und than hash it again with a function B which will get different salts every time you connect to the server. On the server the hashed Password will also be rehashed with B. Then you can compare the clients and servers hash. It's very easy to implement, and it does not store the password in plaintext on the server, but instead as a hash!


Share this post


Link to post
Share on other sites
If you do double hashing, the initial hash of the password becomes the new "must know" secret.

I have an article on Game Authentication and Passwords that you might want to read.

However, the easy solution is to just use a well-understood protocol, such as SSL, and use a solid, existing implementation, such as OpenSSH. That way, your chances of screwing up will be minimized.

Share this post


Link to post
Share on other sites
Quote:
Original post by hplus0603
If you do double hashing, the initial hash of the password becomes the new "must know" secret.

I have an article on Game Authentication and Passwords that you might want to read.

However, the easy solution is to just use a well-understood protocol, such as SSL, and use a solid, existing implementation, such as OpenSSH. That way, your chances of screwing up will be minimized.


Yeah, but I can't think of any way to get around having some sort of "must-know" secret. I read through your link, and it looks like whether you use Challenge Hash Authentication (what I suggested) or Secret Exchange Authentication, you can use whatever info is in the server (password or hash) to login to the server.

Share this post


Link to post
Share on other sites
Thanks a lot! I should have thought of Wikipedia as a starting point, I guess I was too eager to dive in. I did leave out the fact that the server doesn't actually store the password, it decrypts the information sent to it by the client and sends that to an LDAP server for authentication. Am I right in thinking nagromo's suggestion of public key is the right way to go? The whole Bob encrypts something which only Alice can decrypt seems to be what I need.

In any case, thanks for the help. Now I've got some cryptography reading to catch up on.

Share this post


Link to post
Share on other sites
If all you want to do is verify a password and/or establish a shared session key for cryptography there's a very good protocol for that. You can then feed this secret shared key into a symmetric cipher and have a secure channel.

Secure Remote Password Protocol

Share this post


Link to post
Share on other sites
you can use a small encryption method, easily encryoted/decrypted.
I did a small algorithm for a pretty fast and easy encryption/decryption.
you generate a random key per character, for this key u generate a random
number which means the choice of a an operation done on this key and the selected character. u store the result, the encrypted key and the operation nbr.
u do this for every character. send the info or compress and send.
on the server:
-decompress
- reverse the operation on the result and key
- repeat for all characters

I do not know how much this is secure because i m not really into cryptography but i found it easy to implement and compress :)

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!