public async Task <BloggerOutGoingInfo> Register(BloggerRegisteringInfo bloggerRegisteringInfo) { Blogger blogger = await _dbContext.Bloggers .Where(x => x.BloggerEmail == bloggerRegisteringInfo.BloggerEmail) .FirstOrDefaultAsync(); if (blogger != null) { BloggerIncomingInfo bloggerIncomingInfo = new BloggerIncomingInfo() { BloggerEmail = bloggerRegisteringInfo.BloggerEmail, BloggerPassword = bloggerRegisteringInfo.BloggerPassword, }; BloggerOutGoingInfo bloggerOutGoingInfo = await Authenticate(bloggerIncomingInfo); return(bloggerOutGoingInfo); } RNGCryptoServiceProvider rng = new RNGCryptoServiceProvider(); byte[] saltByteText = new byte[96]; rng.GetBytes(saltByteText); Blogger newBlogger = new Blogger() { BloggerEmail = bloggerRegisteringInfo.BloggerEmail, BloggerFullName = bloggerRegisteringInfo.BloggerFullName, BloggerDOB = bloggerRegisteringInfo.BloggerDOB }; newBlogger.BloggerSalt = Convert.ToBase64String(saltByteText); string passwordWithSalt = bloggerRegisteringInfo.BloggerPassword + newBlogger.BloggerSalt; HashAlgorithm algorithm = new SHA256Managed(); newBlogger.BloggerPasswordHash = Convert.ToBase64String(algorithm.ComputeHash( Encoding.UTF8.GetBytes(passwordWithSalt))); await _dbContext.Bloggers.AddAsync(newBlogger); await _dbContext.SaveChangesAsync(); return(await Register(bloggerRegisteringInfo)); }
public Task SaveChangesAsync() { return(_context.SaveChangesAsync()); }