public void WriteStringToTxt(string user, string filename, string json) { try { var dc = new DesCryption(); if (!System.IO.Directory.Exists(System.Environment.CurrentDirectory + "\\data\\" + user + "\\")) { System.IO.Directory.CreateDirectory(System.Environment.CurrentDirectory + "\\data\\" + user + "\\"); } System.IO.File.WriteAllText(System.Environment.CurrentDirectory + "\\data\\" + user + "\\" + filename + ".txt", dc.EncryptString(json, "A1B2C3D4"), System.Text.Encoding.UTF8); } catch { } }
public string ReadStringFromTxt(string user, string filename) { try { var dc = new DesCryption(); if (System.IO.Directory.Exists(System.Environment.CurrentDirectory + "\\data\\" + user + "\\")) { string str = System.IO.File.ReadAllText(System.Environment.CurrentDirectory + "\\data\\" + user + "\\" + filename + ".txt", System.Text.Encoding.UTF8); return(dc.DecryptString(str, "A1B2C3D4")); } else { return(""); } } catch { return(""); } }
public void WriteStringToTxt(string user, string filename, string json) { try { var dc = new DesCryption(); if (!System.IO.Directory.Exists(System.Environment.CurrentDirectory + "\\data\\" + user + "\\")) { System.IO.Directory.CreateDirectory(System.Environment.CurrentDirectory + "\\data\\" + user + "\\"); } System.IO.File.WriteAllText(System.Environment.CurrentDirectory + "\\data\\" + user + "\\" + filename + ".txt", dc.EncryptString(json,"A1B2C3D4"), System.Text.Encoding.UTF8); } catch { } }
public string ReadStringFromTxt(string user, string filename) { try { var dc = new DesCryption(); if (System.IO.Directory.Exists(System.Environment.CurrentDirectory + "\\data\\" + user + "\\")) { string str = System.IO.File.ReadAllText(System.Environment.CurrentDirectory + "\\data\\" + user + "\\" + filename + ".txt", System.Text.Encoding.UTF8); return dc.DecryptString(str,"A1B2C3D4"); } else { return ""; } } catch { return ""; } }
private void btnLogin_Click(object sender, EventArgs e) { lblInfomation.Text = ""; if (cboName.Text.Length < 4) return; if (txtPwd.Text.Length < 4) return; if (txtRandCode.TextLength < 4) return; btnLogin.Enabled = false; btnLogin.Text = "正在登录"; Application.DoEvents(); string name = cboName.Text; string pwd = txtPwd.Text; var htmlTran = new HTML_Translation(); //采用同步方式登录 _la.PostData = string.Format(@"loginUserDTO.user_name={0}&userDTO.password={1}&randCode={2}", name, pwd, txtRandCode.Text); var strHash = _la.BeginLogin(); string strHtml = ""; var cookie = new CookieContainer(); if (strHash == null) { MessageBox.Show("难道12306又挂了?", "提示", MessageBoxButtons.OK, MessageBoxIcon.Question); return; } foreach (var v in strHash.Keys) { cookie = (CookieContainer)v; strHtml = strHash[v].ToString(); break; } if (strHtml == "") { lblInfomation.Text = "登录失败!"; btnLogin.Enabled = true; btnLogin.Text = "登录"; txtRandCode.Focus(); GetRandCodeImg(); return; } try { var returnString = htmlTran.TranslationHtmlEx(strHtml); if (returnString["messages"].Any()) { GetRandCodeImg(); DeterMineCall(() => { lblInfomation.Text = returnString["messages"][0].ToString(); txtRandCode.Text = ""; btnLogin.Enabled = true; btnLogin.Text = "登录"; txtRandCode.Focus(); Application.DoEvents(); }); return; } //var loginCheck = returnString["data"] as JavaScriptObject; if (returnString["data"] != null && returnString["data"]["loginCheck"].ToString() == "Y") { if (chkUserInfo.Checked) { var dc = new DesCryption(); ConfigInfo.conf.username = name; ConfigInfo.conf.password = dc.EncryptString(pwd, name); ConfigInfo.savetofile(ConfigInfo.conf.username); string path = AppDomain.CurrentDomain.BaseDirectory + "data\\" + name; if (!System.IO.Directory.Exists(path)) System.IO.Directory.CreateDirectory(path); LocalCookie.WriteCookiesToDisk(path + "\\usrCookie.cfg", LoginAction.cookieContainer); } btnLogin.Enabled = true; btnLogin.Text = "登录"; this.Hide(); var selectForm = new formSelectTicket(cookie) { ThisCookie = cookie, /*formSelectTicket.cookieContainer = cookie;*/ UserName = cboName.Text }; selectForm.Show(); } else { GetRandCodeImg(); lblInfomation.Text = "登录失败"; txtRandCode.Text = ""; btnLogin.Enabled = true; btnLogin.Text = "登录"; txtRandCode.Focus(); return; } } catch (Exception) { MessageBox.Show("23:00至07:00为系统维护时间!", "温馨提醒", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } finally { } }
private void LoginMain_Load(object sender, EventArgs e) { GetAutoCompleteSource(); if (_nameSource != null) { cboName.Items.AddRange(_nameSource); } var dc = new DesCryption(); cboName.Text = ConfigInfo.conf.username; if (cboName.Text != string.Empty) txtPwd.Text = dc.DecryptString(ConfigInfo.conf.password, ConfigInfo.conf.username); formLogin_Shown(); }