简体   繁体   中英

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. 2.You take a different window by type .. If you could help me would be very grateful, as I'm quite lost ... Thank you!

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.

  • Install your database
  • Install your logintable and your data (eg admin / adminpwd; user / userpwd etc)

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.

If Web application:

  • Create a simple login html form, asking for username and password
  • 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...)

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! ;)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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