I am trying to make a multi user login system for my java program, at the moment i am compairing the username and password to md5 hashes stored in a text file. I would like to be able to geive different users different access wrights to the program, using the system i am using at the moment the accesablility would be easy to change if the text file was opend. Is there a way I could encrypt the text in the file and then unencrypt it when the user loggs in??? Thanks
-
Can you use a database instead? – johnny Nov 24 '10 at 16:11
-
I am new to java so I dont know how to use/make a database with java, but it sounds like a good way to solve the problem!!! – Harry Martland Nov 24 '10 at 16:12
4 Answers
You can take a look at this comprehensive Java Cryptography guide. However, I think that you would be better off with a database to store the username and password since a text file could be easily deleted or modified. Encrypting it only makes it tougher to read.
Please take a look here and here to learn about JDBC. If you want a more robust framework, you can use and ORM like hibernate. The links I have posted refer to MySQL. It is a very popular Database server and integrates well with Java. You shouldn't have any problems finding tutorials or any kind of help with MySQL.
- 51,780
- 5
- 72
- 96
Also have a look at JAAS to restrict access to your services (e.g. based on roles).
- 37,247
- 13
- 80
- 152
-
Here a link how to configure a JDBCRealm in GlassFish: http://blogs.sun.com/swchan/entry/jdbcrealm_in_glassfish – Puce Nov 24 '10 at 16:29
Md5 is a one way hash algorithmic you cant decrypt it back , best way is to compare the encrypted string to validate things
- 15,684
- 43
- 105
- 161
-
The system is offline so it would have to be stored on the computer. Thanks – Harry Martland Nov 24 '10 at 16:14