2

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

Harry Martland
  • 595
  • 2
  • 13
  • 23

4 Answers4

1

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.

npinti
  • 51,070
  • 5
  • 71
  • 94
1

Also have a look at JAAS to restrict access to your services (e.g. based on roles).

Puce
  • 36,099
  • 12
  • 75
  • 145
  • 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
0

Md5 is a one way hash algorithmic you cant decrypt it back , best way is to compare the encrypted string to validate things

Sudantha
  • 14,804
  • 42
  • 102
  • 158
0

Does this help:

Java - encrypt / decrypt user name and password from a configuration file

Community
  • 1
  • 1
johnny
  • 18,831
  • 49
  • 151
  • 252