Archived
基本完成登陆验证 同一JSESSIONID多次登录导致需要验证码??
This commit is contained in:
@@ -14,7 +14,6 @@ using System.Windows.Forms;
|
||||
namespace CSS_Solution.Forms
|
||||
{
|
||||
|
||||
|
||||
partial class MainForm : Form
|
||||
{
|
||||
public MainForm()
|
||||
|
||||
+36
-12
@@ -28,14 +28,17 @@
|
||||
/// </summary>
|
||||
private void InitializeComponent()
|
||||
{
|
||||
components = new System.ComponentModel.Container();
|
||||
Welcome = new Label();
|
||||
password = new TextBox();
|
||||
ID = new TextBox();
|
||||
MainPanel = new Panel();
|
||||
info = new Label();
|
||||
countdown = new Countdown();
|
||||
test = new Button();
|
||||
Record = new Button();
|
||||
record = new Button();
|
||||
SavePassword = new CheckBox();
|
||||
errorInfo_CountDown = new System.Windows.Forms.Timer(components);
|
||||
MainPanel.SuspendLayout();
|
||||
SuspendLayout();
|
||||
//
|
||||
@@ -80,9 +83,10 @@
|
||||
//
|
||||
// MainPanel
|
||||
//
|
||||
MainPanel.Controls.Add(info);
|
||||
MainPanel.Controls.Add(countdown);
|
||||
MainPanel.Controls.Add(test);
|
||||
MainPanel.Controls.Add(Record);
|
||||
MainPanel.Controls.Add(record);
|
||||
MainPanel.Controls.Add(SavePassword);
|
||||
MainPanel.Controls.Add(password);
|
||||
MainPanel.Controls.Add(Welcome);
|
||||
@@ -93,6 +97,17 @@
|
||||
MainPanel.Size = new Size(1403, 736);
|
||||
MainPanel.TabIndex = 3;
|
||||
//
|
||||
// info
|
||||
//
|
||||
info.AutoSize = true;
|
||||
info.ForeColor = Color.White;
|
||||
info.Location = new Point(86, 450);
|
||||
info.Name = "info";
|
||||
info.Size = new Size(91, 24);
|
||||
info.TabIndex = 7;
|
||||
info.Text = "SomeInfo";
|
||||
info.Visible = false;
|
||||
//
|
||||
// countdown
|
||||
//
|
||||
countdown.BackColor = Color.FromArgb(25, 25, 25);
|
||||
@@ -111,17 +126,19 @@
|
||||
test.TabIndex = 5;
|
||||
test.Text = "验证密码";
|
||||
test.UseVisualStyleBackColor = false;
|
||||
test.Click += test_Click;
|
||||
//
|
||||
// Record
|
||||
// record
|
||||
//
|
||||
Record.BackColor = Color.FromArgb(25, 25, 25);
|
||||
Record.ForeColor = Color.White;
|
||||
Record.Location = new Point(86, 393);
|
||||
Record.Name = "Record";
|
||||
Record.Size = new Size(112, 34);
|
||||
Record.TabIndex = 4;
|
||||
Record.Text = "保存密码";
|
||||
Record.UseVisualStyleBackColor = false;
|
||||
record.BackColor = Color.FromArgb(25, 25, 25);
|
||||
record.ForeColor = Color.White;
|
||||
record.Location = new Point(86, 393);
|
||||
record.Name = "record";
|
||||
record.Size = new Size(112, 34);
|
||||
record.TabIndex = 4;
|
||||
record.Text = "保存密码";
|
||||
record.UseVisualStyleBackColor = false;
|
||||
record.Click += record_Click;
|
||||
//
|
||||
// SavePassword
|
||||
//
|
||||
@@ -135,6 +152,11 @@
|
||||
SavePassword.UseVisualStyleBackColor = true;
|
||||
SavePassword.CheckedChanged += SavePassword_CheckedChanged;
|
||||
//
|
||||
// errorInfo_CountDown
|
||||
//
|
||||
errorInfo_CountDown.Interval = 5000;
|
||||
errorInfo_CountDown.Tick += errorInfo_CountDown_Tick;
|
||||
//
|
||||
// Welcome_Form
|
||||
//
|
||||
AutoScaleDimensions = new SizeF(11F, 24F);
|
||||
@@ -159,8 +181,10 @@
|
||||
private Panel MainPanel;
|
||||
private FontDialog fontDialog1;
|
||||
private CheckBox SavePassword;
|
||||
private Button Record;
|
||||
private Button record;
|
||||
private Button test;
|
||||
private Countdown countdown;
|
||||
private Label info;
|
||||
private System.Windows.Forms.Timer errorInfo_CountDown;
|
||||
}
|
||||
}
|
||||
@@ -1,13 +1,17 @@
|
||||
using Microsoft.Extensions.Logging;
|
||||
using CSS_Solution.Request;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Data;
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
using System.Security.Cryptography;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Forms;
|
||||
using System.Xml.Serialization;
|
||||
using static System.Windows.Forms.VisualStyles.VisualStyleElement.StartPanel;
|
||||
|
||||
namespace CSS_Solution.Forms
|
||||
{
|
||||
@@ -16,9 +20,17 @@ namespace CSS_Solution.Forms
|
||||
public Welcome_Form()
|
||||
{
|
||||
InitializeComponent();
|
||||
if (Program.exceptionHandler == null)
|
||||
Initialize.default_logger.LogError($"[{DateTime.Now}] exceptionHandler为空?どうやって?");
|
||||
else
|
||||
Application.ThreadException += Program.exceptionHandler.ApplicationThreadExceptionHandler;
|
||||
|
||||
}
|
||||
private Font normal_font = new Font("Microsoft YaHei UI", 15F, FontStyle.Regular, GraphicsUnit.Point, 134);
|
||||
private Font italic_font = new Font("Microsoft YaHei UI", 15F, FontStyle.Italic, GraphicsUnit.Point, 134);
|
||||
private MD5 MD5 = MD5.Create();
|
||||
private SHA1 SHA1 = SHA1.Create();
|
||||
|
||||
private void ID_Enter(object sender, EventArgs e)
|
||||
{
|
||||
if (ID.Font != normal_font)
|
||||
@@ -64,15 +76,110 @@ namespace CSS_Solution.Forms
|
||||
private void SavePassword_CheckedChanged(object sender, EventArgs e)
|
||||
{
|
||||
|
||||
if (sender == null||save_disk_info_showed)
|
||||
if (sender == null || save_disk_info_showed)
|
||||
return;
|
||||
CheckBox? checkBox = sender as CheckBox;
|
||||
if (checkBox == null) return;
|
||||
if(checkBox.Checked)
|
||||
if (checkBox.Checked)
|
||||
{
|
||||
save_disk_info_showed = true;
|
||||
MessageBox.Show("注意,密码确实会保存为密文,但是该密文可直接用于登录网站(教务管理系统),理想状态下,该密码应当仅保存在内存中。");
|
||||
}
|
||||
}
|
||||
private void record_Click(object sender, EventArgs e)
|
||||
{
|
||||
try
|
||||
{
|
||||
var (username, password) = Code_Preprocess();
|
||||
Code_Save(username, password);
|
||||
if (MessageBox.Show("是否进行一次登录测试,以确保账号密码正确?", "测试输入?", MessageBoxButtons.YesNo) == DialogResult.Yes)
|
||||
Task.Run(() => Code_TestAsync());
|
||||
else
|
||||
Show_info("信息已记录");
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Show_info(ex.Message);
|
||||
}
|
||||
}
|
||||
private void test_Click(object sender, EventArgs e)
|
||||
{
|
||||
try
|
||||
{
|
||||
var (username, password) = Code_Preprocess();
|
||||
if(username!=Settings.etc.Username||password!=Settings.etc.Password)
|
||||
Code_Save(username ,password);
|
||||
Task.Run(()=>Code_TestAsync());
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Show_info(ex.Message);
|
||||
}
|
||||
}
|
||||
private void Code_Save(string username, string password)
|
||||
{
|
||||
if (SavePassword.CheckState == CheckState.Checked)
|
||||
Settings.etc.Write_Code_To_File(username, password);
|
||||
Settings.etc.Username = username;
|
||||
Settings.etc.Password = password;
|
||||
}
|
||||
private async Task Code_TestAsync()
|
||||
{
|
||||
Invoke(() => info.Text = "测试中,可能需要一点时间");
|
||||
bool status = false;
|
||||
string error_info = "";
|
||||
await Task.Run(() =>
|
||||
{
|
||||
bool not_done = true;
|
||||
try
|
||||
{
|
||||
Task_handler.index_Task_Handler.Make_request((result) =>
|
||||
{
|
||||
Task_handler.login_Task_Handler.Make_request((fresult) =>
|
||||
{
|
||||
not_done = false;
|
||||
status = !fresult.isError();
|
||||
error_info = fresult.Error_info;
|
||||
}, result);
|
||||
});
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
status = false;
|
||||
error_info = ex.Message;
|
||||
}
|
||||
while (not_done) ;
|
||||
});
|
||||
Invoke(() => { if (status) Show_info("测试成功"); else Show_info("测试失败" + error_info); });
|
||||
}
|
||||
private (string,string) Code_Preprocess()
|
||||
{
|
||||
string username = ID.Text, password = this.password.Text;
|
||||
if (username == null || username.Length == 0)
|
||||
throw new InvalidOperationException("账号不能为空");
|
||||
if (password == null || password.Length == 0)
|
||||
throw new InvalidOperationException("怕密码泄露可以不用");
|
||||
password = username + password;
|
||||
username = Convert.ToHexString(MD5.ComputeHash(Encoding.UTF8.GetBytes(username))).ToLower();
|
||||
password = Convert.ToHexString(SHA1.ComputeHash(Encoding.UTF8.GetBytes(password))).ToLower();
|
||||
if (!Settings.etc.Agree_use)
|
||||
if (MessageBox.Show("你需要为自己造成的后果负责,同一个账号的大量请求可不是什么正常的事,作者不会也无法对任何后果负责", "Are you sure about that?", MessageBoxButtons.YesNo) == DialogResult.No)
|
||||
throw new Exception("Wise choice");
|
||||
else
|
||||
Settings.etc.Do_Agree_use();
|
||||
return (username, password);
|
||||
}
|
||||
private void errorInfo_CountDown_Tick(object sender, EventArgs e)
|
||||
{
|
||||
errorInfo_CountDown.Enabled = false;
|
||||
info.Visible = false;
|
||||
}
|
||||
private void Show_info(string s)
|
||||
{
|
||||
info.Text = s;
|
||||
info.Visible = true;
|
||||
errorInfo_CountDown.Enabled = true;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -117,4 +117,7 @@
|
||||
<resheader name="writer">
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<metadata name="errorInfo_CountDown.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
|
||||
<value>17, 17</value>
|
||||
</metadata>
|
||||
</root>
|
||||
Reference in New Issue
Block a user