C
C#•6mo ago
Lulers

Learning DB and Identity

Good afternoon friends, I have a CSC Bachelors however I never learned C# and am now picking the subject up to try and utilize my degree to become a backend C# dev. I am very passionate about it, and although I gained no experience after my graduation 4 years ago, I decided to change the course of my life and teach myself (With the help of one friend who is in the field) and gain the needed experience to become a full time backend C# dev. I am currently working on a practice project, backend system for a nutrition tracking / diet assistant web based app with ASP.NET. The reason I am making the post is I would like to get some guidance on what path I should take to learn the subjects of Microsoft SQL database and the Identity library to be implemented into my practice project. What I am thinking is to implement a database, and then after that is implemented, to learn Identity and adjust the DB to work together with it. The thing is however, I never implemented these before with C#, and I am curious if I am making a mistake implementing the first over the other. To save me hours of backtracking, what would you suggest to be the best approach for learning these subjects and to implement them into a project I will upload to my github?
13 Replies
Shazanman
Shazanman•6mo ago
Best approach would be reading about in the Microsoft docs Start here for identity https://learn.microsoft.com/en-us/aspnet/core/security/authentication/identity?view=aspnetcore-8.0&tabs=visual-studio I assumed you are using asp.net
Introduction to Identity on ASP.NET Core
Use Identity with an ASP.NET Core app. Learn how to set password requirements (RequireDigit, RequiredLength, RequiredUniqueChars, and more).
Shazanman
Shazanman•6mo ago
Correct me if I'm wrong Should be straightforward Comment here if you run into problems while following it People will come in to help out
Lulers
LulersOP•6mo ago
Oh turns out Identity has a built in DB functionality. That makes sense. I will read through it soon when I will be coding, and I assume after I implement Identity, I can adjust / change the DB to fit my needs
Shazanman
Shazanman•6mo ago
yes it does
Pobiega
Pobiega•6mo ago
specifically, Identity can use a very commonly used database library/ORM called EF Core they provide their own baseclass to use for your custom DbContext called IdentityDbContext<T> its perfectly fine to learn how to use EF without identity first, if you want to focus on that but its also fine to just dive in with both at the same time
Lulers
LulersOP•6mo ago
Thank you for your response, What I currently am trying to practice on is creating a DB model for a table called "UserProfile" to hold profile information that is important for backend functionality, but not for authentication or registration. As I understood using the documentation and some ChatGPT is that (and correct me if I am totally misunderstanding that) Identity will automatically create a bunch of tables, one of them being 'AspNetUsers' that will contain all the required fields for the library, and then I can manually edit my UserProfile table to connect the keys between them, as opposed to creating a custom UserInfo table and custom design it to fit the Identity library criteria. I am going to start working on it later after work tonight, so I still didnt get a chance to dive into it in practice and to get an understanding of what exactly I dont understand 🙂 And yeah, thats what I've started learning, Entity Framework Core
Pobiega
Pobiega•6mo ago
Sort of You make your own user model that inherits and extends IdentityUser Then use that as your generic T in the context definition Boom, identity now stores your user info there And everything "just works"
Lulers
LulersOP•6mo ago
I see, so basically I would create that if I need to edit the generic user table identity would create, but if I will be fine with Identity's generic AspNetUsers and I would just use it's forein key to connect to my UserProfile table (which is not supposed to store any login information, it basically extends the user profile for other data like user age, weight, height etc) and leave it as is I guess, I think.
Pobiega
Pobiega•6mo ago
That's one way, sure. Not sure I'd personally bother separating the two, but you can
Lulers
LulersOP•6mo ago
Having all of that data in one table would be conventionally safe? I.e the logic credentials, and other data to be used by the backend for nutrition tracking, BMI calculation etc? I was under the impression it would be safer to separate the two, but then again, ChatGPT told me so, and if I learned anything from Terminator, is not to rely on AI And thank you so much for the responses, this is super helpful!!!
Pobiega
Pobiega•6mo ago
as long as they are in the same DB, I dont see how one is safer than the other I suppose I could see a point if a major part of your app is being able to gather info on your users, but you want to make sure you dont accidentally include username/password etc
Lulers
LulersOP•6mo ago
Yeah that makes sense. Weekly analytics, etc. I will look into that after the general DB items and Identity works. Thanks! I appreciate the help. I will be on it tonight
Pobiega
Pobiega•6mo ago
np good luck 🙂
Want results from more Discord servers?
Add your server