예제 #1
0
        public async Task <(string token, DateTime expiration)> CreateJWT(CredentialsDTO credentials)
        {
            try
            {
                var user = await _context.Users.FirstOrDefaultAsync(c => c.Email == credentials.Email);

                if (user != null)
                {
                    var(verified, needsUpgrade) = _pwHasher.Check(user.Password, credentials.Password);
                    if (verified)
                    {
                        if (needsUpgrade)
                        {
                            user.Password = _pwHasher.Hash(credentials.Password);
                            await _context.SaveChangesAsync();
                        }

                        return(_tokenHelper.GenerateJWT(user.Id, user.Email));
                    }
                }

                return(null, DateTime.MinValue);
            }
            catch
            {
                throw;
            }
        }