Beispiel #1
0
        public async Task <SignInResult> SignIn(string email, string password)
        {
            if (_accountAccess.UserExists(email))
            {
                int id = _accountAccess.GetUserId(email);

                EncryptedPassword pass = _accountAccess.GetEncryptedPassword(id);
                if (PasswordEncryptor.PasswordCorrect(password, pass))
                {
                    var claims = new List <Claim>
                    {
                        new Claim(ClaimTypes.Name, email),
                        new Claim(ClaimTypes.NameIdentifier, id.ToString()),
                        new Claim("newDay", true.ToString())
                    };

                    var claimsIdentity = new ClaimsIdentity(
                        claims, CookieAuthenticationDefaults.AuthenticationScheme);

                    var authProperties = new AuthenticationProperties
                    {
                        AllowRefresh = true,
                        ExpiresUtc   = DateTimeOffset.UtcNow.AddMinutes(10),
                        IsPersistent = true,
                        IssuedUtc    = DateTime.UtcNow,
                        RedirectUri  = "./Home/Index"
                    };

                    await _httpContextAccessor.HttpContext.SignInAsync(CookieAuthenticationDefaults.AuthenticationScheme, new ClaimsPrincipal(claimsIdentity), authProperties);

                    return(SignInResult.Succeeded);
                }
                else
                {
                    return(SignInResult.PasswordIncorrect);
                }
            }
            else
            {
                return(SignInResult.EmailIncorrect);
            }
        }
Beispiel #2
0
        public static EncryptedPassword GetPassword(IAccountAccess accountAccess, string email)
        {
            int userId = accountAccess.GetUserId(email);

            return(accountAccess.GetEncryptedPassword(userId));
        }