I am building web application where i am building the first stage with user registration and login.
I am thinking of
class User
{
private userid;
private firstname
.........
//getters and setters
}
class UserService {
public boolean authenticate(username, password) {}
public addUser()
public saveuser()
public ConfirmEmail()
public resetPassword()
......
}
I have few questions
- Is my approach correct?
- Also i have diff function in front end and for backend admin user, so should i put all in one class or, i have to make diff for front end and backend?
- As this is the most common thing which every organisation requires, so is it possible to find it from internet so that i can see how enterprise people approach this?
First thing, I’d look at whether you can use another authentication system like Google or Facebook, or Open ID (StackOverflow uses these and more).
Secondly, I’d look into using a security framework like Spring Security.
Finally, if you want/need to do it on your own from scratch, here are some pointers
I’m assuming you’re using a database. Here’s an example schema (MySQL)
That’ll do it for a very basic user model. You’ll need a tool to generate your salt. I’d use randomAlphanumeric from Apache commons lang.
You may want to add some stuff to lock user accounts after too many failed login attempts. And you may want to track the IP with which they’ve logged in from. This is left as an exercise to the reader 🙂
I added the is_mail_authenticated field to track whether the user had authenticated their mail. This is usually accomplished by clicking a link from one’s email.