liveBook · Manning

Credential

As explained in Pro ASP.NET Core 7, Tenth Edition

An authentication credential is information, such as a username and password, presented to verify a user's identity.

An authentication credential is information presented to establish a user's identity. In the standard username-and-password case, the username is public while the password is known only by the user. Authentication must happen before authorization can decide whether that user may access a feature. section 39.2

ASP.NET Core applications submit credentials to an authentication endpoint. A login form posts the values to an AccountController action, where SignInManager and UserManager authenticate the user. Failed authentication returns a model-validation error; successful authentication redirects to the requested URL. section 11.4

A practical credential flow includes these concerns:

  • Collect the username and password in a view model, requiring both values through model validation. section 11.4
  • Post the credentials over the login form and protect the request with an antiforgery token. section 11.4
  • Keep authentication on the server; client-side validation can improve feedback but must not authenticate users. section 11.4
  • Persist successful authentication in a cookie for later requests, or use bearer tokens for web services and JavaScript clients. section 39.6

SportsStore login

A user requesting a restricted page is redirected to /Account/Login. The GET action supplies a LoginModel and return URL; the POST action validates the submitted credentials, signs the user in when they are correct, and redirects back to the original destination. section 11.4

Listing 11.12 The LoginModel.cs file in the SportsStore/Models/ViewModels folder
using System.ComponentModel.DataAnnotations;

namespace SportsStore.Models.ViewModels {

   public class LoginModel {
       
       public required string Name { get; set; }
               
       public required string Password { get; set; }
               
       public string ReturnUrl { get; set; } = "/";
   }
}

Inspect the LoginModel definition to see the credential fields and return URL used by the login workflow. section 11.4

How Pro ASP.NET Core 7, Tenth Edition covers it

How deep it goes
Defines username/password credentials and follows validation through sign-in, while deferring deeper Identity service mechanics.
Examples
Uses a SportsStore login form, LoginModel, AccountController, validation errors, redirects, and an administrative logout link.
What it assumes
Assumes basic ASP.NET Core MVC, views, model validation, and authorization concepts while introducing authentication’s identity boundary.
What you can do after
Apply credentials through ASP.NET Core Identity to authenticate users and redirect successful logins.
How it connects
Connects authentication with authorization, ASP.NET Core Identity, SignInManager, cookies, and bearer tokens.

Also explained in

Compare how 7 books explain credential →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Pro ASP.NET Core 7, Tenth Edition. The section links point to the parts of the book it draws on.