private void checkonline() { context = new DockerUserControllerEntities(); while (true) { Ping p = new Ping(); PingReply pr = p.Send("8.8.8.8"); if (pr.Status != IPStatus.Success) { Thread.Sleep(500); continue; } if (loginmsg == string.Empty) { Thread.Sleep(500); continue; } else { string[] cookie = loginmsg.Split('^'); string username = cookie[1]; var result = context.UserSet.SingleOrDefault(m => m.Username == username); if (result == null) { loginmsg = ""; } else { string decode = EnDeCode.DecryptString(cookie[0], result.EncodeKey); if (decode != cookie[1]) { loginmsg = ""; } } } Thread.Sleep(600000); } }
private async void button20_Click(object sender, EventArgs e) { if (loginmsg == "") { MessageBox.Show("必须登录才能生成加密文件", "Error", MessageBoxButtons.OK); return; } string[] log = loginmsg.Split('^'); string username = log[1]; var result = await context.UserSet.SingleOrDefaultAsync(m => m.Username == username); if (result == null) { loginmsg = ""; return; } List <List <List <string> > > peizhi = new List <List <List <string> > >(); peizhi.Add(DockerConnectionStrs); peizhi.Add(OpenstackConnectionStrs); StringBuilder sb = new StringBuilder(); for (int i = 0; i < peizhi.Count; i++) { for (int j = 0; j < peizhi[i].Count; j++) { for (int k = 0; k < peizhi[i][j].Count; k++) { sb.Append("," + peizhi[i][j][k]); } } } string neirong = sb.ToString().Substring(1, sb.Length - 1); string encodeedneirong = EnDeCode.EncryptString(neirong, result.EncodeKey); textBox2.Text = encodeedneirong; }
private void button1_Click(object sender, EventArgs e) { //TransfEvent(textBox1.Text); if (!online) { MessageBox.Show("未能成功连接至服务器", "Error", MessageBoxButtons.OK); return; } string user = textBox1.Text; string pass = textBox2.Text; if (user != "" && pass != "") { Regex r = new Regex(@"^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$"); bool ismail = r.IsMatch(user); if (ismail) { var resultforemail = context.EditSet.SingleOrDefault(m => m.Email == user); if (resultforemail == null) { MessageBox.Show("没有此邮箱", "Error", MessageBoxButtons.OK); return; } else { string trueusername = resultforemail.Username; var resultforlogin = context.UserSet.SingleOrDefault(m => m.Username == trueusername); if (resultforlogin.Password != pass) { MessageBox.Show("错误的密码", "Error", MessageBoxButtons.OK); return; } else { cookie = EnDeCode.EncryptString(resultforlogin.Username, resultforlogin.EncodeKey) + "^" + resultforlogin.Username; TransfEvent(cookie); context.Dispose(); Close(); } } } else { var result = context.UserSet.SingleOrDefault(m => m.Username == user); if (result == null) { MessageBox.Show("没有此用户", "Error", MessageBoxButtons.OK); return; } else { if (pass == result.Password) { cookie = EnDeCode.EncryptString(user, result.EncodeKey) + "^" + user; TransfEvent(cookie); context.Dispose(); Close(); } else { MessageBox.Show("密码错误", "Error", MessageBoxButtons.OK); return; } } } } else { if (user == "") { MessageBox.Show("用户名不能为空", "Error", MessageBoxButtons.OK); } else if (pass == "") { MessageBox.Show("密码不能为空", "Error", MessageBoxButtons.OK); } return; } }
private void button2_Click(object sender, EventArgs e) { if (!online) { MessageBox.Show("未能成功连接至服务器", "Error", MessageBoxButtons.OK); return; } string user = textBox1.Text; string pass = textBox2.Text; if (user != "" && pass != "") { var result = context.UserSet.SingleOrDefault(m => m.Username == user); if (result != null) { MessageBox.Show("已经有相同的用户名", "Error", MessageBoxButtons.OK); return; } ConfromPass cp = new ConfromPass(); cp.TransfEvent += ConformP; cp.ShowDialog(); if (conformpass != pass) { MessageBox.Show("密码不相符", "Error", MessageBoxButtons.OK); return; } else { UserSet us = new UserSet { Username = user, Password = pass, EncodeKey = keynumber.ToString() }; context.UserSet.Add(us); EditSet es = new EditSet { Username = user, Identity = 3 }; context.EditSet.Add(es); CloudEditSet ces = new CloudEditSet { Username = user }; context.CloudEditSet.Add(ces); context.SaveChanges(); cookie = EnDeCode.EncryptString(user, keynumber.ToString()) + "^" + user; TransfEvent(cookie); Close(); } } else { if (pass == "") { MessageBox.Show("密码不能为空", "Error", MessageBoxButtons.OK); } else if (user == "") { MessageBox.Show("用户名不能为空", "Error", MessageBoxButtons.OK); } return; } }
private async void button21_Click(object sender, EventArgs e) { string[] neirong = textBox2.Text.Split(','); if (neirong.Count() == 1) { if (loginmsg == "") { MessageBox.Show("必须以导出用户登录才能导入", "Error", MessageBoxButtons.OK); return; } string username = loginmsg.Split('^')[1]; var result = await context.UserSet.SingleOrDefaultAsync(m => m.Username == username); string key = result.EncodeKey; string decodeed = string.Empty; try { decodeed = EnDeCode.DecryptString(textBox2.Text, key); } catch { MessageBox.Show("必须以导出用户登录才能导入", "Error", MessageBoxButtons.OK); return; } neirong = decodeed.Split(','); } List <string> aa = new List <string>(); aa = neirong.ToList(); //aa,docker,false,http://www,adsf,docker,true,http://wwwss,123,qwe,wq,openstack,http://www1,1,1 restart : for (int i = 0; i < aa.Count(); i++) { if (aa.Count() == 0) { break; } if (aa[i + 1] == "docker") { if (aa[i + 2] == "false") { List <string> constr = new List <string>(); constr.Add(aa[i]); constr.Add(aa[i + 1]); constr.Add(aa[i + 2]); constr.Add(aa[i + 3]); DockerConnectionStrs.Add(constr); aa.RemoveRange(0, 4); goto restart; } else if (aa[i + 2] == "true") { List <string> constr = new List <string>(); constr.Add(aa[i]); constr.Add(aa[i + 1]); constr.Add(aa[i + 2]); constr.Add(aa[i + 3]); constr.Add(aa[i + 4]); constr.Add(aa[i + 5]); DockerConnectionStrs.Add(constr); aa.RemoveRange(0, 6); goto restart; } } else if (aa[i + 1] == "openstack") { List <string> constr = new List <string>(); constr.Add(aa[i]); constr.Add(aa[i + 1]); constr.Add(aa[i + 2]); constr.Add(aa[i + 3]); constr.Add(aa[i + 4]); OpenstackConnectionStrs.Add(constr); aa.RemoveRange(0, 5); goto restart; } } MessageBox.Show("成功", "MSG", MessageBoxButtons.OK); comboBox1.Items.Clear(); comboBox2.Items.Clear(); foreach (List <string> a in DockerConnectionStrs) { comboBox1.Items.Add(a[0]); } foreach (List <string> a in OpenstackConnectionStrs) { comboBox2.Items.Add(a[0]); } }