Beispiel #1
0
        public AdminAuthResponse Auth(AdminAuthRequest request)
        {
            AddFirstAdmin();
            var response = new AdminAuthResponse()
            {
                Errors = new List <string>()
            };
            var admin = context.Admins.FirstOrDefault(a => a.Login == request.Login);

            if (admin != null)
            {
                var passwordHash = Convert.ToBase64String(Pbkdf2(request.Password, Convert.FromBase64String(admin.Salt)));
                if (passwordHash != admin.PasswordHash)
                {
                    response.Errors.Add("Неверный пароль");
                }
                else
                {
                    response.Key   = passwordHash;
                    response.Login = request.Login;
                }
            }
            else
            {
                response.Errors.Add("Неверный логин");
            }
            return(response);
        }
        public AdminAuthResponse AdminAuthorization(AdminAuthRequest request)
        {
            var response = adminService.Auth(request);

            if (response.IsSuccessfull)
            {
                HttpContext.Response.Cookies.Append("Login", response.Login);
                HttpContext.Response.Cookies.Append("Key", response.Key);
            }
            return(adminService.Auth(request));
        }