Home > Software engineering >  Site with different authentication for site students and staff in Django?
Site with different authentication for site students and staff in Django?

Time:02-10

I am trying to create a Django web app with two types of users, Students and Staff. The problem is Students must login with their full name and id number (where name is non-unique, and id number operates as password), but I do not believe there is a way for Django to allow name to be non-unique (USERNAME_FIELD constant must be unique). Staff have a different login, they can login with regular username and password (username must be unique). Also, because there are two types of users, I do not know what to put for the AUTH_USER_MODEL constant in settings.py, since there can only be one model for this. What is the best way to set up the app without running into these problems?

CodePudding user response:

If I understood your question properly, you want to keep the usernames of students "non-unique" and you want to differentiate them with unique passwords (Id number).

Django doesn't allow this because it is not a good practice. Why don't you consider keeping "Id number" and "name" as a password (which is again not a good practice to keep "name" as a password but will work in Django)?

Otherwise, if you want to do what you are trying to do, then you can code your own method for authentication instead of using Django's inbuilt method. This may not be that secure but I think your approach itself is not secure so this might work for you.

  •  Tags:  
  • Related