public AuthenticationResponse Authenticate(AuthenticationRequest authenticationRequest) { // First validate the request, UserName and Password are required. if (!ValidateRequest(authenticationRequest)) { return(new AuthenticationResponse { status = false, authToken = "" }); } // Validate user credentials var userProfile = _loginRepository.Authenticate(authenticationRequest.userName, authenticationRequest.password); if (userProfile != null && userProfile.UserKey > 0) //User is authenticated { var loginTime = _loginRepository.SaveUserSession(userProfile.UserKey, true); //TODO: Generate AuthToken var authToken = GenerateAuthToken(); return(new AuthenticationResponse { status = true, authToken = authToken, userDisplayName = userProfile.UserName }); } else { return(new AuthenticationResponse { status = false, authToken = "" }); } }
public IActionResult Authenticate([FromBody] Login model) { var user = _ILoginRepository.Authenticate(model.Username, model.Password); if (user == null) { return(BadRequest(new { message = "Username or password is incorrect" })); } return(Ok(user)); }
public async Task <ActionResult> Login([FromBody] LoginRequest loginRequest) { if (ModelState.IsValid) { var userExists = await _context.Authenticate(loginRequest); if (userExists) { var token = _context.CreateToken(loginRequest); var response = await _context.CreateResponse(loginRequest, token); return(Ok(JsonConvert.SerializeObject(response))); } } return(Unauthorized()); }
public IActionResult Authenticate([FromBody] AuthenticateModel model) { var user = _loginRepository.Authenticate(model.Username, model.Password); if (user == null) { return(BadRequest(new { message = "Username or password is incorrect" })); } var tokenHandler = new JwtSecurityTokenHandler(); byte[] key = null; if (Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT").Equals("Development")) { key = Encoding.ASCII.GetBytes(Env.GetInstance().Dict["JWT_SECRET"]); } else { key = Encoding.ASCII.GetBytes(Environment.GetEnvironmentVariable("JWT_SECRET")); } var tokenDescriptor = new SecurityTokenDescriptor { Subject = new ClaimsIdentity(new Claim[] { new Claim(ClaimTypes.Name, user.UserId.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.UserId, Username = user.Username, Token = tokenString })); }
public async Task <UserDto> Authenticate(string username, string password) { if (string.IsNullOrEmpty(username) || string.IsNullOrEmpty(password)) { return(null); } string sPasswordMD5 = Cryptography.GetMd5Hash(password); //traer datos del usuario en base de datos var user = await _loginRepository.Authenticate(username, sPasswordMD5); // Verifica si el usuario existe if (user == null) { return(null); } //IEnumerable<PRO_RESOURCES> entitiesResources = await _loginRepository.ResourcesRead(user.NIDPROFILE, NTYPERESOURCE); var userDtos = _mapper.Map <UserDto>(user); // Autenticacion existosa return(userDtos); }
public dynamic Authenticate(string UserName, string Password) { var user = _loginRespository.Authenticate(UserName, Password); return(user); }