File tree Expand file tree Collapse file tree 2 files changed +16
-5
lines changed
CommonLibrary/BasicSupport Expand file tree Collapse file tree 2 files changed +16
-5
lines changed Original file line number Diff line number Diff line change @@ -89,6 +89,11 @@ public JsonSettings()
8989 /// 上次系统登录的密码
9090 /// </summary>
9191 public string Password { get ; set ; } = "" ;
92+ /// <summary>
93+ /// 上次系统登录的时间
94+ /// </summary>
95+ public DateTime LoginTime { get ; set ; } = DateTime . Now ;
96+
9297
9398 /// <summary>
9499 /// 当前计算机的机器码,用来判定参数是否是正确的
@@ -107,6 +112,7 @@ public override string ToSaveString()
107112 json . Add ( nameof ( Password ) , new JValue ( Password ) ) ;
108113 json . Add ( nameof ( IsNewVersionRunning ) , new JValue ( IsNewVersionRunning ) ) ;
109114 json . Add ( nameof ( SystemInfo ) , new JValue ( SystemInfo ) ) ;
115+ json . Add ( nameof ( LoginTime ) , new JValue ( LoginTime ) ) ;
110116 return json . ToString ( ) ;
111117 }
112118 public override void LoadByString ( string content )
@@ -119,6 +125,7 @@ public override void LoadByString(string content)
119125 LoginName = SoftBasic . GetValueFromJsonObject ( json , nameof ( LoginName ) , LoginName ) ;
120126 IsNewVersionRunning = SoftBasic . GetValueFromJsonObject ( json , nameof ( IsNewVersionRunning ) , IsNewVersionRunning ) ;
121127 Password = SoftBasic . GetValueFromJsonObject ( json , nameof ( Password ) , Password ) ;
128+ LoginTime = SoftBasic . GetValueFromJsonObject ( json , nameof ( LoginTime ) , LoginTime ) ;
122129 }
123130 }
124131
Original file line number Diff line number Diff line change @@ -49,11 +49,14 @@ private void FormLogin_Shown(object sender, EventArgs e)
4949 {
5050 IsWindowShow = true ;
5151
52- //加载数据
53- textBox_userName . Text = UserClient . JsonSettings . LoginName ?? "" ;
54- textBox_password . Text = UserClient . JsonSettings . Password ?? "" ;
55- checkBox_remeber . Checked = UserClient . JsonSettings . Password != "" ;
56-
52+ //如果七天未登录,账户密码清除
53+ if ( ( DateTime . Now - UserClient . JsonSettings . LoginTime ) . TotalDays < 7 )
54+ {
55+ //加载数据
56+ textBox_userName . Text = UserClient . JsonSettings . LoginName ?? "" ;
57+ textBox_password . Text = UserClient . JsonSettings . Password ?? "" ;
58+ checkBox_remeber . Checked = UserClient . JsonSettings . Password != "" ;
59+ }
5760 //初始化输入焦点
5861 if ( UserClient . JsonSettings . Password != "" ) userButton_login . Focus ( ) ;
5962 else if ( UserClient . JsonSettings . LoginName != "" ) textBox_password . Focus ( ) ;
@@ -230,6 +233,7 @@ private void ThreadCheckAccount()
230233 //登录成功,进行保存用户名称和密码
231234 UserClient . JsonSettings . LoginName = textBox_userName . Text ;
232235 UserClient . JsonSettings . Password = checkBox_remeber . Checked ? textBox_password . Text : "" ;
236+ UserClient . JsonSettings . LoginTime = DateTime . Now ;
233237 UserClient . JsonSettings . SaveToFile ( ) ;
234238
235239
You can’t perform that action at this time.
0 commit comments