title: What is the best way to know which user was authenticated correctly?
body: <p>I am a beginner</p>
  
  <p>A week ago I'm developing a web application in ASP.NET (C #) and using Entity Framework, the application consists of a simple Login system and a series of windows to insert, update delete and select information from the database which brings I get a series of roles (Administrator and Common User). Once the project is completed the idea is that it is housed on a server and can be used by many people</p>
  
  <p>Hata now I have two somewhat silly questions but I want to clear once and for all:</p>
  
  <p>How to know which user has entered? That is, if I enter the correct user and password, in what way will I make a SELECT, an INSERT, an UPDATE or a DELETE? What I do is to make a simple SELECT to the ID (Primary key) taking into account that the user and password match and save this value (INT) in the Session variable:</p>
  
  <pre><code>HttpContext context = HttpContext.Current;
  context.Session["identifier"] = primaryKey;
  </code></pre>
  
  <p>But I recently read this <strong><a href="https://support.microsoft.com/en-us/help/301240/how-to-implement-forms-based-authentication-in-your-asp.net-application-by-using-c-.net" rel="nofollow noreferrer">article</a></strong>. It's here when we talk about cookies... even encryption.</p>
  
  <ul>
  <li>What is the safest and most effective way to save the user's
  reference?</li>
  <li>If there are users administrators, writers, consultants, etc. How do
  I design the forms? for example, administrators can publish but common users
  can only query information. Will I have to design multiple forms for
  each role?</li>
  </ul>
  
  <p>I have thought that the primary key (which is an integer) should not be necessary but rather the user's email or nickname</p>