-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* added nuspec * switch back to csproj from nuspec * added some help to disable default options * refactor spv * refactored tests * updated ver num * added some doc comments, renamed NoDefaults for clarity's sake * Sample app (#6) * bootsrapped example app * added basic auth scheme * replaced example app with sample app * updated nuget pkg * updated nuget * updated to stable * Update README.md added usage and installation sections
- Loading branch information
Showing
15 changed files
with
252 additions
and
25 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
using System.Threading.Tasks; | ||
using Microsoft.AspNetCore.Identity; | ||
using Microsoft.AspNetCore.Mvc; | ||
using SampleApp.Models; | ||
using SampleApp.Models.DTO; | ||
|
||
namespace SampleApp.Controllers | ||
{ | ||
[Route("api/[action]")] | ||
[ApiController] | ||
public class AccountController : ControllerBase | ||
{ | ||
// GET api/values | ||
private readonly UserManager<AppUser> _userManager; | ||
|
||
public AccountController(UserManager<AppUser> userManager) | ||
{ | ||
_userManager = userManager; | ||
} | ||
|
||
[HttpPost] | ||
public async Task<IActionResult> Register([FromBody] AppUserDTO userDto) | ||
{ | ||
var user = new AppUser {UserName = userDto.Username}; | ||
var registrationResult = await _userManager.CreateAsync(user, userDto.Password); | ||
return registrationResult.Succeeded ? Ok() : (IActionResult) BadRequest(registrationResult.Errors); | ||
} | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
using Microsoft.EntityFrameworkCore; | ||
using SampleApp.Models; | ||
|
||
namespace SampleApp.Data | ||
{ | ||
public class AppDbContext : DbContext | ||
{ | ||
public AppDbContext(DbContextOptions<AppDbContext> options) : base(options) | ||
{ | ||
} | ||
|
||
public DbSet<AppUser> AppUsers { 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
using Microsoft.AspNetCore.Identity; | ||
|
||
namespace SampleApp.Models | ||
{ | ||
public class AppUser : IdentityUser | ||
{ | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
namespace SampleApp.Models.DTO | ||
{ | ||
public class AppUserDTO | ||
{ | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
using Microsoft.AspNetCore; | ||
using Microsoft.AspNetCore.Hosting; | ||
|
||
namespace SampleApp | ||
{ | ||
public class Program | ||
{ | ||
public static void Main(string[] args) | ||
{ | ||
CreateWebHostBuilder(args).Build().Run(); | ||
} | ||
|
||
public static IWebHostBuilder CreateWebHostBuilder(string[] args) => | ||
WebHost.CreateDefaultBuilder(args) | ||
.UseStartup<Startup>(); | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<Project Sdk="Microsoft.NET.Sdk.Web"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>netcoreapp2.2</TargetFramework> | ||
<AspNetCoreHostingModel>InProcess</AspNetCoreHostingModel> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Microsoft.AspNetCore.App" /> | ||
<PackageReference Include="Microsoft.AspNetCore.Razor.Design" Version="2.2.0" PrivateAssets="All" /> | ||
<PackageReference Include="StanfordPasswordPolicy" Version="1.0.0" /> | ||
</ItemGroup> | ||
|
||
</Project> |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
using Microsoft.AspNetCore.Builder; | ||
using Microsoft.AspNetCore.Hosting; | ||
using Microsoft.AspNetCore.Identity; | ||
using Microsoft.AspNetCore.Mvc; | ||
using Microsoft.EntityFrameworkCore; | ||
using Microsoft.Extensions.Configuration; | ||
using Microsoft.Extensions.DependencyInjection; | ||
using SampleApp.Data; | ||
using SampleApp.Models; | ||
using StanfordPasswordPolicy; | ||
|
||
namespace SampleApp | ||
{ | ||
public class Startup | ||
{ | ||
public Startup(IConfiguration configuration) | ||
{ | ||
Configuration = configuration; | ||
} | ||
|
||
public IConfiguration Configuration { get; } | ||
|
||
// This method gets called by the runtime. Use this method to add services to the container. | ||
public void ConfigureServices(IServiceCollection services) | ||
{ | ||
services.AddDbContext<AppDbContext>(opt => opt.UseInMemoryDatabase(databaseName: "SampleAppDb")); | ||
|
||
services.AddIdentity<AppUser, IdentityRole>(opt => | ||
{ | ||
opt.Password = StanfordPasswordValidatorBase.NoDefaultPasswordOptions; | ||
} | ||
) | ||
.AddEntityFrameworkStores<AppDbContext>() | ||
.AddDefaultTokenProviders() | ||
.AddPasswordValidator<StanfordPasswordValidator<AppUser>>(); | ||
|
||
services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_2); | ||
} | ||
|
||
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. | ||
public void Configure(IApplicationBuilder app, IHostingEnvironment env) | ||
{ | ||
if (env.IsDevelopment()) | ||
{ | ||
app.UseDeveloperExceptionPage(); | ||
} | ||
|
||
app.UseMvc(); | ||
} | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
{ | ||
"Logging": { | ||
"LogLevel": { | ||
"Default": "Debug", | ||
"System": "Information", | ||
"Microsoft": "Information" | ||
} | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{ | ||
"Logging": { | ||
"LogLevel": { | ||
"Default": "Warning" | ||
} | ||
}, | ||
"AllowedHosts": "*" | ||
} |
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
using System.Linq; | ||
using Microsoft.AspNetCore.Identity; | ||
|
||
namespace StanfordPasswordPolicy | ||
{ | ||
public abstract class StanfordPasswordValidatorBase | ||
{ | ||
public static class ErrorCode | ||
{ | ||
public static readonly string ShortLength = "ShortPassword"; | ||
public static readonly string NoSymbol = "NoSymbols"; | ||
public static readonly string NoNumber = "NoNumbers"; | ||
public static readonly string NoMixedCase = "NotMixedCase"; | ||
} | ||
|
||
/// <summary> | ||
/// A clear set of PasswordOptions, to reset Identity's defaults, since StanfordPasswordValidator ignores these options. | ||
/// </summary> | ||
public static PasswordOptions NoDefaultPasswordOptions => | ||
new PasswordOptions | ||
{ | ||
RequireDigit = false, | ||
RequiredLength = 0, | ||
RequiredUniqueChars = 1, | ||
RequireLowercase = false, | ||
RequireNonAlphanumeric = false, | ||
RequireUppercase = false | ||
}; | ||
|
||
protected static bool CheckMixedCase(string password) => | ||
password.Any(char.IsUpper) && password.Any(char.IsLower); | ||
|
||
protected static bool CheckNumber(string password) => password.Any(char.IsNumber); | ||
|
||
protected static bool CheckSymbol(string password) => !password.All(char.IsLetterOrDigit); | ||
} | ||
} |
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