예제 #1
0
        public async Task <User> Authenticate(LoginModel loginData)
        {
            var user = await _userRepository.GetLogin(loginData.Username);

            if (user == null)
            {
                throw new ApplicationException("Usuário incorreto");
            }

            bool isPasswordCorrect = _encrypter.compare(user.Password, loginData.Password);

            if (!isPasswordCorrect)
            {
                throw new ApplicationException("Senha incorreta");
            }

            user.Token = _jwtGenerator.GenerateJwt(loginData.Username);
            return(user);
        }