简体   繁体   English

使用 MySQL 在用户 Java 中进行身份验证

[英]Authentication in user Java with MySQL

I have to make an application after a login, take you to a window with a few options, which change according to the type of user you been logged (administrator, manager, normal user), I've created the login dialog and connected to the database, but do not know how to do that: 1.Java distinguish a user is admin, manager or normal.我必须在登录后创建一个应用程序,带你到一个有几个选项的窗口,这些选项根据你登录的用户类型(管理员、经理、普通用户)而变化,我已经创建了登录对话框并连接到数据库,但是不知道怎么做: 1.Java区分一个用户是admin、manager还是normal。 2.You take a different window by type .. If you could help me would be very grateful, as I'm quite lost ... Thank you! 2.您按类型选择不同的窗口..如果您能帮助我将不胜感激,因为我很迷茫......谢谢!

Okey, as you don't tell the application base (if web application, desktop application, used framework etc) then I will need to be very simple in my answer.好吧,因为您没有告诉应用程序基础(如果是 Web 应用程序、桌面应用程序、使用的框架等),那么我的答案将需要非常简单。

  • Install your database安装你的数据库
  • Install your logintable and your data (eg admin / adminpwd; user / userpwd etc)安装您的登录表和您的数据(例如 admin / adminpwd; user / userpwd 等)

If Swing:如果摇摆:

  • Create a login-window that asks for username and password创建一个要求用户名和密码的登录窗口
  • If admin then load admin-frame, if user load user-frame otherwise show error.如果 admin 则加载 admin-frame,如果用户加载 user-frame 否则显示错误。

If Web application:如果 Web 应用程序:

  • Create a simple login html form, asking for username and password创建一个简单的登录html表单,要求输入用户名和密码
  • Do a user check in your Jsp/Servlet, put user-info in session and redirect to user-page if user, to admin-page if admin, otherwise error-page (you could make a simple check in pages to verify that user-info exists in session, in case of...)做一个用户检查你的 Jsp/Servlet,把用户信息放在会话中,如果是用户,则重定向到用户页面,如果是管理员,则重定向到管理页面,否则重定向到错误页面(您可以在页面中进行简单的检查以验证用户-信息存在于会话中,以防...)

This is a very very basic flow, you could of course make a group/role table/column that connects each user to a group.这是一个非常非常基本的流程,您当然可以制作一个将每个用户连接到一个组的组/角色表/列。 Which makes it easier when you have plenty of users.当您拥有大量用户时,这会更容易。 There are many frameworks out there that makes this easier, but the basics are the same!有许多框架可以使这变得更容易,但基础是相同的! ;) ;)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM