Spring Security project. The database has a unique column by name. If a new user is registered under the existing nickname, then we get:

whitelabel eror.

What is logical. I want to ask, where is the best place to check for the existence of the Login field? In the servlet, when we create a new user? Or maybe the script from the page itself should go to the MySQL database and check when the user types the login?

  • It can be done both by the script and in the servlet, but when creating a new user, verification should be mandatory (or we handle the exception existence of a login). - MrFylypenko

1 answer 1

Naturally Servlet -

 User user = userService.findUserByName(username); if (user == null { model.addAttribute("error", "Can't find username. Check login/password"); } 
  • CustomPerson customPerson = personService.getPersonByLogin (login); if (customPerson! = null) {model.addAttribute ("error", "this login is used"); - Victor Morozov