//insert a data to database public async Task <Values> AddValue(Values value) { await _context.Values.AddAsync(value); await _context.SaveChangesAsync(); return(value); }
public async Task <User> Register(User user, string password) { CreatePasswordHash(password, out byte[] passwordSalt, out byte[] passwordHash); user.PasswordSalt = passwordSalt; user.PasswordHash = passwordHash; await _datingDbContext.Users.AddAsync(user); await _datingDbContext.SaveChangesAsync(); return(user); }
public async Task <IActionResult> Create([Bind("Id,FirstName,LastName,Age,Gender,Sexuality,ImageFile,Presentation,IsActive")] ProfileModel profileModel) { if (ModelState.IsValid) { //Vi sparar vår bild till foldern Image i wwwroot string wwwPath = _hostEnvironment.WebRootPath; string file = Path.GetFileNameWithoutExtension(profileModel.ImageFile.FileName); string extension = Path.GetExtension(profileModel.ImageFile.FileName); profileModel.ImageFilepath = file = file + DateTime.Now.ToString("yymmddss") + extension; string path = Path.Combine(wwwPath + "/Image/", file); using (var fileStream = new FileStream(path, FileMode.Create)) { await profileModel.ImageFile.CopyToAsync(fileStream); } //Lägger till det vi sparat _context.Add(profileModel); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(profileModel)); }
public async Task <User> Register(User user, string password) { //passwordHash is encrypted password //passwordSlat is the key for encrypting and decrypting the password byte[] passwordHash, passwordSalt; //hash the password CreatePasswordHash(password, out passwordHash, out passwordSalt); //assign to user object user.PasswordHash = passwordHash; user.PasswordSalt = passwordSalt; //save to database await _context.User.AddAsync(user); await _context.SaveChangesAsync(); return(user); }
public static async Task SeedUser(DatingDbContext context) { if (await context.Users.AnyAsync()) { return; } var userData = await File.ReadAllTextAsync("Data/UserSeedData.json"); var users = JsonSerializer.Deserialize <List <AppUser> >(userData); users?.ForEach(item => { using var hmac = new HMACSHA512(); item.UserName = item.UserName.ToLower(); item.PasswordHash = hmac.ComputeHash(Encoding.UTF8.GetBytes("Pa$$w0rd")); item.PasswordSalt = hmac.Key; context.Users.Add(item); }); await context.SaveChangesAsync(); }
public async Task <bool> SaveAll() { return(await _datingDbContext.SaveChangesAsync() > 0); }