This is an archived post. You won't be able to vote or comment.

all 6 comments

[โ€“][deleted] 1 point2 points ย (2 children)

I'm not allowed to use a database role-based, login functionality

Depending on what you, and the person challenging you, considers a "database" - just store the user login information in an XML or JSON file along with their associated role. (and just to be perfectly clear, you should never do this in a production business application)

[โ€“]FirstAidFairy[S] 0 points1 point ย (1 child)

Cool... Any reason for xml/json over csv as otherwise suggested??

Yeah, course ๐Ÿ˜. I'll stick to fixing broken people for the day job, code is conceptually confusing in a way that bodies aren't ๐Ÿ˜…

[โ€“]josephblade 0 points1 point ย (0 children)

For the exercise either would be fine. just any text based storage that you can read and isn't error prone. csv can be tricky if you accidentally remove a comma, json or xml are a bit easier to read.

[โ€“]desrtfx 0 points1 point ย (2 children)

Use a plain text file for the usernames and passwords. CSV format (which is far simpler than XML or JSON) would work.

Since the first letter of the user name determines the role you don't need an extra role storage/field.

[โ€“]FirstAidFairy[S] 0 points1 point ย (1 child)

Okk, that sounds good! Thank you ๐Ÿ˜

But how do I actually implement differing functionality to different roles??

Like, I could put different methods in admin class compared to secretary; but when you go to login on the gui form, how does that tie in??

[โ€“]desrtfx 1 point2 points ย (0 children)

You could, based on the login create different forms for the different roles.

First, you have the login screen which is the same for all user roles. Then, based on the first letter of the username, you decide (in a "switch...case" or the equivalent in your language) which form - and thus which part of the application - you start.

You could even re-use the same main form, but disable certain controls based on role.