Problem is the password is not hashed or encrypted in any way. How do I go about adding more security to my method?
Most commonly passwords are hashed using SHA-x or MD-5 hashing algorithms. In such a case developers hash a password and store the hashed copy in the database or code. So there is no human readable copy anywhere.
To authenticate against this password you have to create a HASH of the user entered password and then compare it against the stored password.
If you are creating a web app the hashing can be done in javascript before submitting the webpage, this way a hashed password travels through the network, making it difficult for hackers to intercept and then "un-hash" them
Javascript hashing goes like following (assume we are using md5 and users password is "test")
- generate md 5 of "test" which is 098f6bcd4621d373cade4e832627b4f6 and store it in the db
- On the client side(javascript) retrieve the session-id
- let's say users enters "test" md5 it first so the result is 098f6bcd4621d373cade4e832627b4f6
- md5 it again with the session-id prepended (let's say session id here is 9985) so the new md5 is
f93437292fca0cf9b71bf1f3fe6c4679
- send ONLY the hash to the server
- server can get the session id by using one of the library methods, for example in Java one can get the id by session.getId();
run a query which is similar to the following
select md5(concat(pwd,'9985')) as newpwd from users where uname='xyz'
- match "newpwd" with the user submitted value
If someone tries to post data through HTTP reply the authentication will not go through because the server creates new session id each time.
So if a user logs out and logs back in a new hashed password is sent through the wire.
See the following links for your reference
Python's safest method to store and retrieve passwords from a database
What is the format in which Django passwords are stored in the database?
http://en.wikipedia.org/wiki/Salt_(cryptography)