Winform 记住密码
来源:互联网 发布:vscode调整字体大小 编辑:程序博客网 时间:2024/05/20 19:49
/// <summary>
/// 记录登录信息
/// </summary>
/// <param name="pars">无参数表示"登录"按钮成功事件</param>
public void RememberLoginInfo(params string[] pars)
{
// 声明加密类
DES des = new DES();
UserInfo userList = new UserInfo();
BinaryFormatter bf = new BinaryFormatter();
FileStream fs = null;
string fileName = "data.bin";
string operateName = pars.Length == 0 ? "" : pars[0];
switch (operateName)
{
case "页面加载":
using (fs = new FileStream(fileName, FileMode.OpenOrCreate))
{
if (fs.Length > 0)
{
users = bf.Deserialize(fs) as Dictionary<string, UserInfo>;
}
this.cbUserName.Items.Clear();
// 增加用户名
foreach (UserInfo user in users.Values)
{
this.cbUserName.Items.Add(user.LoginId);
}
if (this.cbUserName.Items.Count > 0)
{
for (int j = 0; j < this.cbUserName.Items.Count; j++)
{
if (users.ContainsKey(this.cbUserName.Items[j].ToString()) && users[this.cbUserName.Items[j].ToString()].Pwd != "")
{
strRecordLogName = this.cbUserName.Items[j].ToString();
this.txtUserPwd.Text = des.Decrypt(users[this.cbUserName.Items[j].ToString()].Pwd);
this.chbRemberPWD.Checked = true;
}
}
}
}
break;
case "用户列表选择事件":
using (fs = new FileStream(fileName, FileMode.OpenOrCreate))
{
if (fs.Length > 0)
{
users = bf.Deserialize(fs) as Dictionary<string, UserInfo>;
}
for (int i = 0; i < users.Count; i++)
{
if (this.cbUserName.Text.Trim() != "")
{
if (users.ContainsKey(this.cbUserName.Text.Trim()) && users[this.cbUserName.Text].Pwd != "")
{
this.txtUserPwd.Text = des.Decrypt(users[this.cbUserName.Text].Pwd);
this.chbRemberPWD.Checked = true;
}
else
{
this.txtUserPwd.Text = ""; ;
this.chbRemberPWD.Checked = false;
}
}
}
}
break;
default:
// "登录"按钮成功事件
using (fs = new FileStream(fileName, FileMode.Create))
{
userList.LoginId = this.cbUserName.Text.Trim();
userList.Pwd = this.chbRemberPWD.Checked ? des.Encrypt(this.txtUserPwd.Text.Trim()) : "";
if (users.ContainsKey(userList.LoginId))
{
users.Remove(userList.LoginId);
}
users.Add(userList.LoginId, userList);
bf.Serialize(fs, users);
}
break;
}
fs.Close();
}
- winform--记住密码
- Winform 记住密码
- winform登陆记住密码
- winform登录窗体实现记住密码功能
- winform登录记住用户和密码
- Winform实现登录窗体记住密码的功能
- 记住密码
- 记住密码
- 记住密码
- 记住密码
- 记住密码
- 记住密码
- 记住密码
- 记住密码
- 记住密码
- 记住密码
- 记住密码
- 记住密码
- [转载]MYSQ数据库CLOB、BLOB存取
- SQL 模糊查询
- java中private, public,protected的区别
- VC makefile 编译
- jetty对cxf的支持,简单的cxf实例
- Winform 记住密码
- Java中static、this、super、final的用法详解
- ps -aux的错误用法
- Android的启动过程: zygote & Services & HomeScreen
- python with关键字用法
- DTS官方博客成立
- Android系统源码数据库(mmssms.db)中几个表之间的关系【转】
- ubuntu11.10 vnc 图形界面问题
- android.os包中相关类的使用[Build,Build.VERSION,SystemClock]