public async Task <IActionResult> Create(User user) { if (!ModelState.IsValid) { return(BadRequest()); } user.password = Cryptic.GetHash(user.password); _context.Users.Add(user); await _context.SaveChangesAsync(); user.password = ""; return(CreatedAtAction(nameof(GetById), new { id = user.Id }, user)); }
public async Task <ActionResult <User> > Validate(User user) { //Ideally this should be in different controller if (!ModelState.IsValid) { return(BadRequest()); } var founduser = await _context.Users.Where(o => o.Name == user.Name).FirstOrDefaultAsync(); if (founduser != null && (Cryptic.GetHash(user.password) == founduser.password)) { user.password = ""; return(user); } return(NotFound()); }
public static void Initialize(UserContext context) { if (!context.Users.Any()) { context.Users.AddRange( new User { Name = "Madison", password = Cryptic.GetHash("Secret") }, new User { Name = "Randy", password = Cryptic.GetHash("Secret2") } );;;; context.SaveChanges(); } }