public IActionResult Authenticate([FromBody] AuthenticateModel model) { var user = _usersRepository.Authenticate(model.Username, model.Password); if (user == null) { return(BadRequest(new { message = "Username or password is incorrect" })); } var tokenHandler = new JwtSecurityTokenHandler(); var key = Encoding.ASCII.GetBytes(_appSettings.Secret); var tokenDescriptor = new SecurityTokenDescriptor { Subject = new ClaimsIdentity(new Claim[] { new Claim(ClaimTypes.Name, user.Id.ToString()) }), Expires = DateTime.UtcNow.AddDays(7), SigningCredentials = new SigningCredentials(new SymmetricSecurityKey(key), SecurityAlgorithms.HmacSha256Signature) }; var token = tokenHandler.CreateToken(tokenDescriptor); var tokenString = tokenHandler.WriteToken(token); // return basic user info and authentication token return(Ok(new { Id = user.Id, Username = user.Username, Token = tokenString })); }
public async Task <IActionResult> Login([FromBody] AuthDto authUser) { var user = await _usersRep.Authenticate(authUser.Username, authUser.Password); if (user == null) { return(Unauthorized()); } var tokenHandler = new JwtSecurityTokenHandler(); var secretKey = new SymmetricSecurityKey(Encoding.ASCII.GetBytes(_appSettings.Secret)); var signinCredentials = new SigningCredentials(secretKey, SecurityAlgorithms.HmacSha512Signature); var tokenDescriptor = new SecurityTokenDescriptor { Subject = new ClaimsIdentity(new Claim[] { new Claim(ClaimTypes.Name, user.Id.ToString()) }), Expires = DateTime.UtcNow.AddDays(3), SigningCredentials = signinCredentials }; var token = tokenHandler.CreateToken(tokenDescriptor); var tokenString = tokenHandler.WriteToken(token); return(Ok(new AuthUserDto { Name = user.Name, Token = tokenString })); }
public IActionResult Authenticate([FromBody] UserDto userDto) { var response = new UserDto(); var serviceResponse = _userRepository.Authenticate(userDto.Username, GenericService.Encrypt(userDto.Password, _appSettings.Value.KeyForEncrypting)); if (serviceResponse == null) { return(BadRequest(new { message = "Username or password is incorrect" })); } // authentication successful so generate jwt token var tokenHandler = new JwtSecurityTokenHandler(); var key = Encoding.ASCII.GetBytes(_appSettings.Value.Secret); var tokenDescriptor = new SecurityTokenDescriptor { Subject = new ClaimsIdentity(new Claim[] { new Claim(ClaimTypes.Name, serviceResponse.UniqueId.ToString()) }), Expires = DateTime.UtcNow.AddDays(1), SigningCredentials = new SigningCredentials(new SymmetricSecurityKey(key), SecurityAlgorithms.HmacSha256Signature) }; var token = tokenHandler.CreateToken(tokenDescriptor); serviceResponse.Token = tokenHandler.WriteToken(token); response = _mapper.Map <UserDto>(serviceResponse); return(Ok(response)); }
public async Task <UserDto> AuthenticateAsync(string username, string password) { _logger?.LogInformation("{0} has been retrieved successfully.", MethodBase.GetCurrentMethod().Name); var userEntity = await _repository.Authenticate(username, password); var response = _mapper.Map <UserDto>(userEntity); return(response); }
public async Task <IActionResult> Authenticate([FromBody] Model.UserForAuthentication userCreds) { var user = await _repo.Authenticate(userCreds.UserEmail, userCreds.Password); if (user == null) { return(BadRequest("Username or password is incorrect")); } var result = _mapper.Map <Model.UserModel>(user); // return basic user info (without password) return(Ok(result)); }
public ActionResult <UserOutputDto> Authenticate([FromBody] AuthenticationInputDto authenticationDto) { var credentials = new Credentials(authenticationDto.Email, authenticationDto.Password); var user = _usersRepository.Authenticate(credentials); if (user == null) { return(Unauthorized(new { message = "Invalid credentials." })); } var token = _securityManager.GenerateToken(user); return(Ok(token)); }
public IActionResult Authenticate(LoginModel userParam) { if (userParam == null) { return(BadRequest("Data is null.")); } var user = usersRepository.Authenticate(userParam.userNickName, userParam.userPassword); if (user == null) { return(BadRequest(new { message = "Username or password is incorrect" })); } return(Ok(user)); }
/// <summary> /// Executa o tratamento do comando /// </summary> /// <param name="message">Comando de autenticação do usuário</param> /// <returns>Resposta da execução do comando</returns> public async Task <Response> Handle(AuthenticateUserCommand message) { try { var password = new Password(message.Password); var user = await _repository.Authenticate(message.Email, password.Encoded); return(user == null ? new Response().AddError("Usuário ou senha inválidos") : new Response(user)); } catch (Exception ex) { return(new Response().AddError(ex.Message)); } }
public async Task <ActionResult <UserModel> > Authenticate([FromBody] UserRequest userRequest) { var user = await _usersRepository.Authenticate(userRequest.Username, userRequest.Password); if (user == null) { return(BadRequest()); } var tokenHandler = new JwtSecurityTokenHandler(); var key = Encoding.ASCII.GetBytes(_appSettings.Secret); var tokenDescriptor = new SecurityTokenDescriptor { Subject = new ClaimsIdentity(new Claim[] { new(ClaimTypes.Name, user.Data.Id.ToString()) }),
public async Task <ActionResult <AuthenticateResponse> > Authenticate(AuthenticateRequest authenticateRequest) { try { var response = await _usersRepository.Authenticate(authenticateRequest); if (response == null) { return(BadRequest(new { message = "Email or password is incorrect" })); } return(Ok(response)); } catch (Exception) { return(StatusCode(StatusCodes.Status500InternalServerError, "Database Failure")); } }
public IList <UserLogin> Authenticate(UsersVo.UserLoginVo UserLogin) { IList <UserLogin> userLogins = new List <UserLogin>(_usersRepository.Authenticate(UserLogin.Login)); // Compar password if (userLogins.Count == 0) { return(userLogins = null); } else if (UserLogin.PassWord.Equals(Encryption.Decrypt(userLogins[0].PassWord))) { userLogins[0].PassWord = UserLogin.PassWord; return(userLogins); } // Return User Login return(userLogins); }
public UsersDto Authenticate(string username, string password) { if (string.IsNullOrEmpty(username) || string.IsNullOrEmpty(password)) { return(null); } var user = _usersRepository.Authenticate(username, password); // check if username exists if (user == null) { return(null); } var userDto = _mapper.Map <UsersDto>(user); // authentication successful return(userDto); }
public async Task <IActionResult> Login([FromBody] AuthRequest request) { try { var result = await _repo.Authenticate(request); if (result == null) { return(BadRequest("Bad login data")); } return(Ok(result)); } catch (Exception e) { Console.WriteLine(e); return(new ObjectResult("Error occured") { StatusCode = 500 }); } }
public ActionResult Login([FromBody] UsersLoginRequestDto user) { if (user == null) { return(BadRequest()); } if (ModelState.IsValid == false) { return(BadRequest()); } // 계정확인 var findUser = _usersRepository.Authenticate(user); if (findUser == null) { return(BadRequest()); } // 토큰발급 Response.Cookies.AppendToken(_config, findUser.EMAIL, HttpContext); return(Ok()); }
public Users Authenticate(string username, string password) { return(_usersRepository.Authenticate(username, password)); }
public UserDto Authenticate(string username, string password) { return(mapper.Map <UserDto>(repository.Authenticate(username, password))); }
public async Task <User> Authenticate(string userName, string password) => await _repository.Authenticate(userName, password);