public void Parse(byte[] headerData, int headerOffset, byte[] bodyData) { BasicHeaderSegment _headerSegment = new BasicHeaderSegment(); _headerSegment.ReadFrom(headerData, headerOffset); if (_headerSegment.OpCode != OpCode.LoginResponse) { throw new InvalidProtocolException("Invalid opcode in response, expected " + OpCode.LoginResponse + " was " + _headerSegment.OpCode); } UnpackState(headerData[headerOffset + 1]); MaxVersion = headerData[headerOffset + 2]; ActiveVersion = headerData[headerOffset + 3]; TargetSessionId = Utilities.ToUInt16BigEndian(headerData, headerOffset + 14); StatusPresent = true; StatusSequenceNumber = Utilities.ToUInt32BigEndian(headerData, headerOffset + 24); ExpectedCommandSequenceNumber = Utilities.ToUInt32BigEndian(headerData, headerOffset + 28); MaxCommandSequenceNumber = Utilities.ToUInt32BigEndian(headerData, headerOffset + 32); StatusClass = headerData[headerOffset + 36]; StatusCode = (LoginStatusCode)Utilities.ToUInt16BigEndian(headerData, headerOffset + 36); TextData = bodyData; }
public static void LogToAttempts(string username, LoginStatusCode statusCode) { var logAttempts = GetAttempts(); if (logAttempts == null) { logAttempts = new List<LogAttempt>(); } logAttempts.Add(new LogAttempt() { Username = username, StatusCode = statusCode }); var json = JsonConvert.SerializeObject(logAttempts, _jsonSettings); File.WriteAllText(_attemptsFile, json); //using(var context = new StudentInfoContext()) //{ // context.Logs.Add( // new LogAttempt // { // Username = username, // StatusCode = statusCode // }); // context.SaveChanges(); //} }
/// <summary> /// Called when a response is received for a pending account login. /// </summary> /// <param name="result">Response data</param> private void AsyncLoginAccountResponse(IAsyncResult result) { LoginStatusCode status = LoginStatusCode.ServerError; Account.AccountLoginResponseModel responseModel = null; var request = result.AsyncState as HttpWebRequest; try { var response = (HttpWebResponse)request.EndGetResponse(result); if (HttpStatusCode.OK == response.StatusCode) { // Grab the account data. var reader = new StreamReader(response.GetResponseStream()); responseModel = JsonConvert.DeserializeObject <Account.AccountLoginResponseModel>(reader.ReadToEnd()); status = LoginStatusCode.Ok; } } catch (WebException ex) { using (HttpWebResponse response = (HttpWebResponse)ex.Response) { switch (response.StatusCode) { case HttpStatusCode.BadRequest: status = LoginStatusCode.MalformedData; break; case HttpStatusCode.NotFound: status = LoginStatusCode.InvalidCredentials; break; case HttpStatusCode.InternalServerError: status = LoginStatusCode.ServerError; break; } } } OnLoginAccountResponse(new LoginResponse(status, responseModel)); }
protected void btnSubmitLogin_Click(object sender, EventArgs e) { if (txtEmail.Value != null && txtEmail.Value != null) { LoginModel loginModel = new LoginModel(); Customer customer = loginModel.signIn(txtEmail.Value, txtPassword.Value); //Throws DALException if (customer != null) { //put user in session and send user back to his last active page Session["user"] = customer; Response.Redirect(Request.RawUrl); txtEmailError.Visible = false; } else { //user couldn't be logged in, request the status code so the correct error can be displayed to the user LoginStatusCode status = loginModel.getLoginStatus(txtEmail.Value, txtPassword.Value); //Throws DALException switch (status) { case LoginStatusCode.NOTVERIFIED: Response.Redirect("NotYetVerified.aspx?email=" + txtEmail.Value); break; case LoginStatusCode.WRONGLOGIN: liLogin.Attributes["Class"] = "dropdown open"; txtEmailError.Visible = true; txtEmailError.Text = "Unknown login name"; break; case LoginStatusCode.WRONGPASSWORD: liLogin.Attributes["Class"] = "dropdown open"; txtEmailError.Visible = true; txtEmailError.Text = "Incorrect login/password combination"; break; } } } }
/// <summary> /// Initializes a new instance of the LoginException class. /// </summary> /// <param name="message">The reason for the exception.</param> /// <param name="code">The target-indicated reason for the exception.</param> public LoginException(string message, LoginStatusCode code) : base("iSCSI login failure (" + code + "):" + message) { }
public LoginMessageServer(LoginStatusCode serverStatusCode) { ServerStatusCode = serverStatusCode; }
public static LoginMessageServer CreateLoginResponse(LoginStatusCode statusCode) { return(new LoginMessageServer(statusCode)); }
public LoginResponse(LoginStatusCode statusCode, LoginUserData userData) { StatusCode = statusCode; UserData = userData; }
internal LoginResponse(LoginStatusCode status, Account.AccountLoginResponseModel model) { Status = status; Model = model; }