plcd gets authentication

I had a short while over the weekend and decided that plcd needed to become more secure...

Until now, plcd has relied in obfuscation in its dealings with authentication, and bearing in mind that this is about the worst way to do it, I decided that there needs to be some form of real authentication involved. I have decided to use a password field in the network thread which will store the password hash.

The network thread has also been updated to maintain a socket's state, when the socket gets connected, it enters the connected state, at which time the network thread sends a nonce string. The client takes the nonce string and the hashed password, hashes them together and sends it back to plcd. If the resultant string is the same as that calculated on the server, the socket is transitioned to the authenticated state, at which point all commands are accepted and acted upon. On disconnect, the socket is moved to the disconnected state and deleted.

At any time, the server can switch the socket back to the connected state (unauthenticated) at which point the client must reauthenticate with the new nonce string. This provides the ability to challenge an authenticated client, and make it requalify.

Subject: