public async Task <ActionResult <Gebruiker> > PostGebruiker(Gebruiker gebruiker) { var salt = HashService.GenerateSalt(); var hashedWachtwoord = HashService.Create(gebruiker.Wachtwoord, salt); gebruiker.Wachtwoord = hashedWachtwoord; gebruiker.Salt = salt; _context.Gebruikers.Add(gebruiker); await _context.SaveChangesAsync(); return(Ok()); }
public async Task <IActionResult> WachtwoordReset(Gebruiker gebruikerNew) { var gebruiker = _context.Gebruikers.Where(g => g.GebruikerID == gebruikerNew.GebruikerID).FirstOrDefault(); if (gebruiker == null) { var gebruikerID = Int32.Parse(User.Claims.FirstOrDefault(c => c.Type == "GebruikerID").Value); gebruiker = _context.Gebruikers.Find(gebruikerID); } var hashedWachtwoord = gebruiker.Wachtwoord; var salt = gebruiker.Salt; if (HashService.Validate(gebruikerNew.Wachtwoord, salt, hashedWachtwoord) == false) { gebruiker.Wachtwoord = HashService.Create(gebruikerNew.Wachtwoord, salt); _context.Entry(gebruiker).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!GebruikerExists(gebruikerNew.GebruikerID)) { return(NotFound()); } else { throw; } } return(NoContent()); } else { return(BadRequest("Dit wachtwoord is hetzelfde als het huidige wachtwoord!")); } }
public static void Initialize(AngularContext context) { context.Database.EnsureCreated(); if (context.Gebruikers.Any()) { return; } var salt = HashService.GenerateSalt(); var gebruikers = new Gebruiker[] { new Gebruiker(context) { Gebruikersnaam = "Wesley", Email = "*****@*****.**", Salt = salt, Wachtwoord = HashService.Create("wesley", salt), ImageUrl = "https://res.cloudinary.com/dnjmym7yo/image/upload/v1574867798/profile_q2bu5r.png" }, new Gebruiker(context) { Gebruikersnaam = "SirTurtle", Email = "*****@*****.**", Salt = salt, Wachtwoord = HashService.Create("sirturtle", salt), ImageUrl = "https://res.cloudinary.com/dnjmym7yo/image/upload/v1574867798/profile_q2bu5r.png" }, new Gebruiker(context) { Gebruikersnaam = "SirFailure", Email = "*****@*****.**", Salt = salt, Wachtwoord = HashService.Create("sirfailure", salt), ImageUrl = "https://res.cloudinary.com/dnjmym7yo/image/upload/v1574867798/profile_q2bu5r.png" }, new Gebruiker(context) { Gebruikersnaam = "Ali", Email = "*****@*****.**", Salt = salt, Wachtwoord = HashService.Create("ali123", salt), ImageUrl = "https://res.cloudinary.com/dnjmym7yo/image/upload/v1574867798/profile_q2bu5r.png" }, new Gebruiker(context) { Gebruikersnaam = "Din", Email = "*****@*****.**", Salt = salt, Wachtwoord = HashService.Create("din123", salt), ImageUrl = "https://res.cloudinary.com/dnjmym7yo/image/upload/v1574867798/profile_q2bu5r.png" }, new Gebruiker(context) { Gebruikersnaam = "Lenny", Email = "*****@*****.**", Salt = salt, Wachtwoord = HashService.Create("lenny123", salt), ImageUrl = "https://res.cloudinary.com/dnjmym7yo/image/upload/v1574867798/profile_q2bu5r.png" }, }; foreach (Gebruiker g in gebruikers) { context.Gebruikers.Add(g); } context.SaveChanges(); }