当前位置:网站首页>WinForm remember password function
WinForm remember password function
2022-07-21 15:16:00 【I Can -Jiang】
Remember the password :
Dictionary<string, User> users = new Dictionary<string, User>();
// Remember the password
private void Password()
{
// Create... Under the execution directory data.bin file , Used to store account and password
FileStream fs = new FileStream("data.bin", FileMode.Create);
BinaryFormatter bf = new BinaryFormatter();
// The account number is automatically saved
user.LoginID = txt_UserID.Text.Trim();
// If checked, remember password , Just save the password , Otherwise, save the null value
if (CB_Rpwd.Checked)
{
user.Pwd = txt_Password.Text.Trim();
}
else
{
user.Pwd = "";
}
if (users.ContainsKey(user.LoginID))
{
users.Remove(user.LoginID);
}
users.Add(user.LoginID, user);
bf.Serialize(fs, users);
fs.Close();
this.Dispose();
}
Enter the account number and bring out the password automatically :
private void txt_UserID_SelectedIndexChanged(object sender, EventArgs e)
{
FileStream fs = new FileStream("data.bin", FileMode.OpenOrCreate);
if (fs.Length > 0)
{
BinaryFormatter bf = new BinaryFormatter();
users = bf.Deserialize(fs) as Dictionary<string, User>;
for (int i = 0; i < users.Count; i++)
{
if (txt_UserID.Text.Trim() != "")
{
if (users.ContainsKey(txt_UserID.Text.Trim()) && users[txt_UserID.Text].Pwd != "")
{
txt_Password.Text = users[txt_UserID.Text].Pwd;
CB_Rpwd.Checked = true;
}
else
{
txt_Password.Text = "";
CB_Rpwd.Checked = false;
}
}
}
}
fs.Close();
}
load Function to load data.bin Inside user Drop down of
private void Frm_Login_Load(object sender, EventArgs e)
{
FileStream fs = new FileStream("data.bin", FileMode.OpenOrCreate);
if (fs.Length > 0)
{
BinaryFormatter bf = new BinaryFormatter();
users = bf.Deserialize(fs) as Dictionary<string, User>;
foreach (User user in users.Values)
{
txt_UserID.Properties.Items.Add(user.LoginID);
}
//for (int i = 0; i < users.Count; i++)
//{
// if (txt_UserID.Text.Trim() != "")
// {
// if (users.ContainsKey(txt_UserID.Text.Trim()))
// {
// txt_Password.Text = users[txt_UserID.Text].Pwd;
// CB_Rpwd.Checked = true;
// }
// }
//}
}
fs.Close();
}
边栏推荐
- 第二章第三节:字符串常规操作
- Arithmetic operator 2 (Gretel software - Jiuye practical training)
- DAMA-第十二章(元数据管理)
- Nacos cluster construction
- Section 3 of Chapter 2: general operation of string
- The relationship between data warehouse and data center
- Kingbasees database administrator's Guide -- 15.2 Manage sequence
- [CVA valuation training camp] read the annual reports of listed companies_ Lesson 2
- SQL: SELECT t.`app_ code`, SUM(t.`success_num`) AS success_ num, SUM(t.`
- 很多人认为元宇宙的发展逻辑和互联网是一致的,但笔者并不觉得
猜你喜欢
随机推荐
Un fantôme.
架构实战营模块 7 作业
调研报告之——可见光通信与可见光定位
魑魅魍魎
第二章第十一节:元组
TCP sliding window explanation (very practical)
On the surface, the meta universe may fundamentally change people's way of production and life
How to solve the garbled Chinese annotation of idea import project
第二章第七节:列表的概念
7.19 simulation summary
Functions of the machine room dynamic loop monitoring system and main functions of the dynamic loop monitoring system
长城证券手机软件线上炒股开户证券公司佣金低?开户安全吗?
C#与SAP接口对接
networkX 可视化图 visibility graph 如何根据时间序列得到图
Hangzhou dynamic environment monitoring system supplier, dynamic environment monitoring equipment
第二章 第四节:替换和切割
Section 12 of Chapter 2: set set
[public class preview]: cloud video conference system privatization practice
[applet] come and develop your first wechat game (detailed process)
Math.random()的用法