C
C#

help

Storing login data

Ccaptainbulba1/30/2023
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.
Eero1/30/2023
"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);
Ccaptainbulba1/30/2023
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);
Aatakancracker1/30/2023
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
Ccaptainbulba1/30/2023
yep, that makes sense. thanks a lot

Looking for more? Join the community!

Want results from more Discord servers?
Add your server
Recommended Posts
❔ EF core - unable to map collection to database❔ AZ-204 wth very low experienceIs there a point in trying to pass AZ-204 with very low Azure experience, i.e. whether i can actuall❔ Entity Framework duplicating primary key with seeded data.I have set up a database with EF6 and as part of verifying that it is working I have seeded in some How to obtain a request verification token cookie using HttpClient?When my browser does a get request for this site, the request obtains a request verification token a❔ new() not available in C# 7.3my error is : *error CS8370: Feature 'target-typed object creation' is not available in C# 7.3. Plea❔ Windows Form, Changing Label.Text says Cannot Implicitly Convert type "void" to "String"Not sure why this is happening. I'll take any help I can get 🙏❔ Can't use TorchSharp nuget packageI must be doing something dumb... but I can't seem to launch a program with torchsharp, i keep getti❔ Properly calling "await login()" in web service constructorHello. Kinda noob, but I am looking for the best way to call a async login function for an external ✅ PowerShell Method in WinUI C#So firstly, yes I have to use Powershell and am unable to just do it in C#. Below will be an examp❔ What is better book for c# mastery? "Pro C# 9 with .NET 5" or "C# 9 and .NET 5"?Hey I want to spend some money on nice paperback editions of programming books that I can use to dra❔ EF Core tries to query a non-existant column for no apparent reasonI am making a simple web API in ASP.NET with MVC. I have the following model Event: ```cs using Sys❔ I keep getting an error " Index was outside the bounds of the array"I've written a method that gets 3 arrays, in which the third one has to have all the numbers merged ❔ Having trouble with a player swap function```cs public void swap() { Vector3 LastPlayerPos = transform.position; ❔ Pannel not showingHello, I have a problem with my winform app, there is a pannel that won't show although I have this ❔ WPF game in C# having trouble attaching the "fireball" (image) to the player(ImagePlayer)https://gyazo.com/d7f93807a3085469eea5e5ac0e7a63da❔ How to adapt text to fit large items in Xamarin.Forms XAML UIHi all, slight problem here: I've got this todo app, it enters and removes todo items just fine, bu❔ LINQ build an array with an arbitrary value at the startSo, I want to make a palette that's an array of `int`s where index 0 is equal to 0 and the rest repe❔ Xamarin Android NFC App Open User Input after Button Clickwe have installed an Git Repository with an NFC Reader Write Applikation and it hase The bUtton Read