This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@page | |
@model IndexModel | |
@{ | |
ViewData["Title"] = "Home page"; | |
} | |
<div> | |
@Model.Message | |
</div> | |
<form method="post"> | |
<div class="form-group"> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using AuthenticationSample.Models; | |
using Microsoft.AspNetCore.Authentication; | |
using Microsoft.AspNetCore.Authentication.Cookies; | |
using Microsoft.AspNetCore.Identity; | |
using Microsoft.AspNetCore.Mvc; | |
using Microsoft.AspNetCore.Mvc.RazorPages; | |
using Microsoft.Extensions.Configuration; | |
using System.Collections.Generic; | |
using System.ComponentModel.DataAnnotations; | |
using System.Security.Claims; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"Logging": { | |
"LogLevel": { | |
"Default": "Warning" | |
} | |
}, | |
"AllowedHosts": "*", | |
"SiteUser": { | |
"UserName": "your user name", | |
"Password": "your hashed password" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
namespace AuthenticationSample.Models | |
{ | |
public class SiteUser | |
{ | |
public string UserName { get; set; } | |
public string Password { get; set; } | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public void ConfigureServices(IServiceCollection services) | |
{ | |
services.Configure<CookiePolicyOptions>(options => | |
{ | |
// This lambda determines whether user consent for non-essential cookies is needed for a given request. | |
options.CheckConsentNeeded = context => true; | |
options.MinimumSameSitePolicy = SameSiteMode.None; | |
}); | |
services.AddAuthentication(CookieAuthenticationDefaults.AuthenticationScheme).AddCookie(cookieOptions => { | |
cookieOptions.LoginPath = "/"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@page | |
@model AuthenticationSample.Pages.Admin.IndexModel | |
@{ | |
} | |
<h1>Admin</h1> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using Microsoft.AspNetCore.Identity; | |
namespace PasswordHasherTest | |
{ | |
class Program | |
{ | |
static void Main(string[] args) | |
{ | |
var passwordHasher = new PasswordHasher<string>(); | |
Console.WriteLine(passwordHasher.HashPassword(null, "strong password")); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
services.Configure<RouteOptions>(options => | |
{ | |
options.ConstraintMap.Add("slug", typeof(SlugParameterTransformer)); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class SlugParameterTransformer : IOutboundParameterTransformer | |
{ | |
public string TransformOutbound(object value) | |
{ | |
return value?.ToString().ToSlug(); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Text; | |
public static class Extensions | |
{ | |
public static string ToSlug(this string value, bool toLower = true) | |
{ | |
if (value == null) | |
return ""; | |
var normalised = value.Normalize(NormalizationForm.FormKD); | |
const int maxlen = 80; | |
int len = normalised.Length; |
NewerOlder