public IHttpActionResult Authenticate([FromBody] AuthenticateRequest dataDocument) { try { if (Request.Headers.Authorization != null) { var headerRequest = new HeaderRequest(Request.Headers.Accept.ToString(), Request.Headers.Authorization.Scheme, Request.Headers.Authorization.Parameter); var action = new AuthenticateAction(headerRequest, dataDocument); return(Ok(action.ActionResult)); } else { HlpLog.Warning(eService.ServiceAuthentication, "", CodeMessages.InvalidHeaderParameters); ResponseStatus response = HlpGenerateResponse.GeneratePostResponse("0400", HlpLog.GetEnumDescription(CodeMessages.InvalidHeaderParameters), "Undefined", string.Empty, "0"); response.Result.Add("Errors", HlpLog.GetEnumDescription(CodeMessages.InvalidHeaderParameters)); return(Ok(response)); } } catch (Exception ex) { ResponseStatus response = HlpGenerateResponse.GeneratePostResponse("0500", HlpLog.GetEnumDescription(CodeMessages.InvalidHeaderParameters), "Undefined", string.Empty, "0"); response.Result.Add("Errors", ex.Message); HlpLog.Error(eService.ServiceAuthentication, "", CodeMessages.InvalidHeaderParameters, ex); return(Ok(response)); } }
public bool Authenticate() { var validateCommand = false; while (!validateCommand) { _chatserver.Write(_client.GetStream(), AuthenticationProtocolValues.CommandPrompt); var data = _chatserver.Read(_client.GetStream()); data = data.Trim(); _action = action_default; if (data.ToUpper().IndexOf(AuthenticationProtocolValues.LoginCommand, StringComparison.Ordinal) == 0) { _action = action_login; validateCommand = true; } if (data.ToUpper().IndexOf(AuthenticationProtocolValues.RegisterCommand, StringComparison.Ordinal) == 0) { _action = action_register; validateCommand = true; } if (!_action()) { return(false); } } _chatserver.Write(_client.GetStream(), AuthenticationProtocolValues.AutenticatedMsg); return(true); }
//Main authentication method public bool Authenticate() { byte[] bytes = new byte[256]; string data = null; bool validate_command = false; //Get user command //Valid command is login and register while (!validate_command) { chatserver.Write(client.GetStream(), AuthenticationProtocolValues.COMMAND_PROMPT); data = chatserver.Read(client.GetStream()); data = data.Trim(); //default action is to assume that the command is invalid action = new AuthenticateAction(action_default); //actions are reassigned based on data entered by user if (data.ToUpper().IndexOf(AuthenticationProtocolValues.LOGIN_COMMAND) == 0) { action = new AuthenticateAction(action_login); validate_command = true; } if (data.ToUpper().IndexOf(AuthenticationProtocolValues.REGISTER_COMMAND) == 0) { action = new AuthenticateAction(action_register); validate_command = true; } //perform the action //if it failed the the process has failed if (!action()) { return(false); } } //While //when out of loop the command has succeed //send the authenticated message to the client chatserver.Write(client.GetStream(), AuthenticationProtocolValues.AUTENTICATED_MSG); return(true); }