public bool SeedDatabase() { bool seedResult = false; var adminInfo = _blogService.GetAdminInfo().Result; if (adminInfo == null) { seedResult = _blogService.SetAdminInfo(new Login { ID = Guid.NewGuid().ToString(), UserName = "******", Password = KiwiCryptography.HashPassword("K!w!Bl0g"), }).Result; } var blogInfo = _blogService.GetBlogInfo().Result; if (blogInfo == null) { seedResult &= _blogService.SetBlogInfo(new BlogInfo { ID = Guid.NewGuid().ToString(), Title = "Kiwi Blog", GithubUsername = "******", LinkedInUsername = "******", TelegramUsername = "******", TwitterUsername = "******", About = "Kiwi blog written by Mojtaba Tajik" }).Result; } return(seedResult); }
public Task <bool> SetAdminInfo(Login loginInfo) { var tempLogin = _loginCollection.FindAll().FirstOrDefault(); if (tempLogin != null) { tempLogin.UserName = loginInfo.UserName; tempLogin.Password = KiwiCryptography.HashPassword(loginInfo.Password); return(Task.FromResult(_loginCollection.Upsert(tempLogin))); } return(Task.FromResult(_loginCollection.Upsert(loginInfo))); }
public async Task <IActionResult> ChangeAdmin(Login login) { if (!ModelState.IsValid) { return(View()); } var adminInfo = await _blog.GetAdminInfo(); if (adminInfo.Password != KiwiCryptography.HashPassword(login.CurrentPassword)) { ModelState.AddModelError(string.Empty, "Current password is incorrect."); return(View()); } var setResult = await _blog.SetAdminInfo(login); return(View("Index")); }
private bool VerifyHashedPassword(string password) { return(KiwiCryptography.HashPassword(password) == LoginInfo.Password); }