Fix massive security bug with display names

This commit is contained in:
Michael 2017-04-10 18:44:29 -04:00
parent 147f266e68
commit 72feceb369
2 changed files with 16 additions and 0 deletions

View file

@ -179,6 +179,16 @@ public async Task<ActionResult> Register(RegisterViewModel model)
{
if (ModelState.IsValid)
{
using(var temp = new ApplicationDbContext())
{
if(temp.Users.FirstOrDefault(x=>x.UserName==model.Username) != null)
{
ModelState.AddModelError("Your display name is already taken.");
return View(model);
}
}
var user = new ApplicationUser { UserName = model.Email, Email = model.Email, DisplayName = model.Username, Codepoints = 0, JoinedAt = DateTime.Now, MutedAt = DateTime.Now, BannedAt = DateTime.Now, LastLogin = DateTime.Now };
var result = await UserManager.CreateAsync(user, model.Password);
if (result.Succeeded)

View file

@ -11,6 +11,12 @@
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0">
@if(ViewBag.PageDescription != null)
{
<meta name="description" content="@ViewBag.PageDescription" />
}
<title>@ViewBag.Title &bull; Project: Unite</title>
@Styles.Render("~/Content/css")
@Styles.Render("~/Content/bootstrap-theme.css")