예제 #1
0
파일: DataSeeder.cs 프로젝트: rasyidf/Kiwi
        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);
        }
예제 #2
0
        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)));
        }
예제 #3
0
        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"));
        }
예제 #4
0
 private bool VerifyHashedPassword(string password)
 {
     return(KiwiCryptography.HashPassword(password) == LoginInfo.Password);
 }