private static string handleCreateSessionRequest(NameValueCollection requestData) { var responseData = HttpUtility.ParseQueryString(""); var validLoginAccount = LoginAccountList.GetValidLogin(requestData["username"], requestData["password"]); if (validLoginAccount != null) { Session newSession = new Session(requestData["username"], DateTime.Now.AddHours(23), Convert.ToBase64String(Guid.NewGuid().ToByteArray())); if (SessionList.TryAddSession(newSession)) { LoggedInUserList.AddOrUpdateLoggedInUser(new LoggedInUser(newSession.LoginUsername, validLoginAccount.Playername, "")); responseData.Add("result", "success"); responseData.Add("token", newSession.Token); responseData.Add("playername", validLoginAccount.Playername); } else { responseData.Add("result", "fail"); } } else { responseData.Add("result", "fail"); } return(responseData.ToString()); }
private static string handleUpdateLoginRequest(NameValueCollection requestData) { var responseData = HttpUtility.ParseQueryString(""); if (LoginAccountList.TryUpdateLogin(requestData["username"], SecurePasswordHasher.Hash(requestData["newpassword"]), requestData["newplayername"], requestData["oldpassword"], requestData["oldplayername"])) { responseData.Add("result", "success"); } else { responseData.Add("result", "fail"); } return(responseData.ToString()); }