java登录系统
我正在尝试为我的java程序制作一个多用户登录系统,目前我正在将用户名和密码与存储在文本文件中的md5哈希值进行比较。我希望能够为不同的用户提供对程序的不同访问权限,使用我目前使用的系统,如果打开文本文件,则可以轻松更改可访问性。有没有办法可以加密文件中的文本,然后在用户登录时解密它???谢谢
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
你可以看看这个全面的 Java 密码学指南。但是,我认为您最好使用数据库来存储用户名和密码,因为文本文件可以轻松删除或修改。对其进行加密只会使其更难以阅读。
请查看这里和此处 了解 JDBC。如果你想要一个更健壮的框架,你可以使用 ORM,比如 hibernate。我发布的链接涉及 MySQL。它是一种非常流行的数据库服务器,并且与 Java 集成良好。您应该不会有任何关于 MySQL 的教程或任何类型的帮助的问题。
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.
还可以查看 JAAS 来限制对您的服务的访问(例如,基于角色)。
Also have a look at JAAS to restrict access to your services (e.g. based on roles).
Md5 是一种单向哈希算法,您无法解密它,最好的方法是比较加密的字符串来验证内容
Md5 is a one way hash algorithmic you cant decrypt it back , best way is to compare the encrypted string to validate things
这是否有帮助:
Java - 加密/解密用户配置文件中的名称和密码
Does this help:
Java - encrypt / decrypt user name and password from a configuration file