Storing login data

Hello everyone! I am trying to build a simple school management system in console. Once a user login I want to store some of the data in order to avoid querying for that data again. What would be the best approach? I thought of using static such as
public static class Login
{
public static string login { get; set; }
public static bool teacherFlag { get; set; }
public static bool adminFlag { get; set; }

}
public static class Login
{
public static string login { get; set; }
public static bool teacherFlag { get; set; }
public static bool adminFlag { get; set; }

}
But from what I read this approach is not good as multiple applications can mix up the information.
4 Replies
ero
ero2y ago
"Multiple applications" can't really mess with your information But i wouldn't do it that way either way. You could just have a "currently logged in user" in your main code flow
record User(
string Username,
bool IsTeacher,
bool IsAdmin);
record User(
string Username,
bool IsTeacher,
bool IsAdmin);
captainbulba
captainbulbaOP2y ago
aha, got it. Thanks Sorry, just to clarify. I would still store my User in the static in order to get info from anywhere. Do I follow it correctly?
public static Pet pet;

// somewhere

pet = new Pet()
{
Name = "Bob",
Age = 12
};

// later

Console.WriteLine("Welcome " + StartMenu.pet.Name);
public static Pet pet;

// somewhere

pet = new Pet()
{
Name = "Bob",
Age = 12
};

// later

Console.WriteLine("Welcome " + StartMenu.pet.Name);
Cracker
Cracker2y ago
that would work, of course if you only have one user, otherwise you can use dictionary with userId as key Multiple applications (meaning other exe instances of console app) not have access to other instances so no worries of mixing up between apps. But if you are setting the Pet from different lines of code then that will be overridden
captainbulba
captainbulbaOP2y ago
yep, that makes sense. thanks a lot
Want results from more Discord servers?
Add your server