本地保存登录账号实现忘记密码及自动登录

  #region 删除本地自动登录及记住密码信息
/// <summary>
/// 删除本地自动登录及记住密码信息
/// </summary>
private void DeleteSelfMotionLoginOrRememberPwd()
{
if (cbAutomatic.Checked == false)
{
if (Directory.Exists("SelfMotionLogin"))
{
if (File.Exists(@"SelfMotionLogin/SelfMotionLoginInfo.xml"))
{
File.Delete(@"SelfMotionLogin/SelfMotionLoginInfo.xml");
}
}
}
if (cbRememberPwd.Checked == false)
{
if (Directory.Exists("RememberPwd"))
{
if (File.Exists(@"RememberPwd\" + txtLoginName.Text + ".xml"))
{
File.Delete(@"RememberPwd\" + txtLoginName.Text + ".xml");
}
}
}
}
#endregion #region 保存自动登录及记住密码到本地事件方法
/// <summary>
/// 保存自动登录及记住密码到本地事件方法
/// </summary>
private void SelfMotionLoginOrRememberPwd()
{ if (cbAutomatic.Checked && cbRememberPwd.Checked)
{
XElement xml = new XElement(
new XElement("LoginInfo",
new XElement("SelfMotionLogin",
new XElement("UserName", txtLoginName.Text),
new XElement("UserPwd", txtLoginPwd.Text)
))
);
xml.Save(@"SelfMotionLogin/SelfMotionLoginInfo.xml");
}
else if (cbRememberPwd.Checked)
{
XElement xml = new XElement(
new XElement("LoginInfo",
new XElement("RememberPwd",
new XElement("UserName", txtLoginName.Text),
new XElement("UserPwd", txtLoginPwd.Text)
))
);
xml.Save(@"RememberPwd/" + txtLoginName.Text + ".xml");
}
}
#endregion #region 获取自动登录及记住密码信息
#region 获取记住密码信息
/// <summary>
/// 获取记住密码信息
/// </summary>
private void GetRememberPwd()
{
if (Directory.Exists("RememberPwd"))
{
if (File.Exists(@"RememberPwd/" + txtLoginName.Text + ".xml"))
{
XElement xml = XElement.Load(@"RememberPwd/" + txtLoginName.Text + ".xml");
var AllInfo = from info in xml.Elements("RememberPwd")
select new Users
{
UserName = info.Element("UserName").Value,
UseuPwd = info.Element("UserPwd").Value
};
if (AllInfo != null)
{
foreach (Users l in AllInfo)
{
txtLoginName.Text = l.UserName;
txtLoginPwd.Text = l.UseuPwd;
cbRememberPwd.Checked = true;
}
}
}
}
}
#endregion #region 获取本地自动登录
/// <summary>
/// 获取本地自动登录
/// </summary>
private void GetSelfMotionLogin()
{
if (Directory.Exists("SelfMotionLogin"))
{
if (File.Exists(@"SelfMotionLogin/SelfMotionLoginInfo.xml"))
{
XElement xml = XElement.Load(@"SelfMotionLogin/SelfMotionLoginInfo.xml");
var AllInfo = from info in xml.Elements("SelfMotionLogin")
select new Users
{
UserName = info.Element("UserName").Value,
UseuPwd = info.Element("UserPwd").Value
};
if (AllInfo != null)
{
foreach (Users l in AllInfo)
{
txtLoginName.Text = l.UserName;
txtLoginPwd.Text = l.UseuPwd;
cbAutomatic.Checked = true;
var checkoutData = from a in am.SelectUsersAll()
where a.UserName == l.UserName
select a;
Users getCheckoutData = new Users();
foreach (var get in checkoutData)
{
getCheckoutData.UserName = get.UserName;
getCheckoutData.UseuPwd = get.UseuPwd;
}
DialogResult dialogResult = MessageBox.Show("你确定要自动登录 [" + txtLoginName.Text + "]吗?", "自动登录提示",
MessageBoxButtons.OKCancel,
MessageBoxIcon.Asterisk);
if (dialogResult == DialogResult.OK)
{
if (txtLoginName.Text != getCheckoutData.UserName)
{
MessageBox.Show("自动登录账号 [" + txtLoginName.Text + "] 不存在!", "登录出错",
MessageBoxButtons.OK,
MessageBoxIcon.Error);
txtLoginName.Focus();
return;
}
if (txtLoginPwd.Text != getCheckoutData.UseuPwd)
{
MessageBox.Show("自动登录密码不正确!", "登录提示",
MessageBoxButtons.OK,
MessageBoxIcon.Asterisk);
txtLoginPwd.Focus();
return;
}
//传值
List<Users> Userss = am.SelectUsersAll().FindAll((p) => p.UserName.IndexOf(txtLoginName.Text) >= );
foreach (Users a in Userss)
{
saveUsersInfo.Name = a.Name;
saveUsersInfo.userNo = a.UNo;
} this.Hide();
FrmMain frm = new FrmMain();
frm.Show();
//List<Users> Users = am.SelectUsersByconn(txtLoginName.Text);
//foreach (Users a in Users)
//{
// Ano = a.ANo;
// Name = a.Name;
//}
}
}
}
}
else
{
timeLogin.Enabled = false;
}
}
else
{
timeLogin.Enabled = false;
}
}
#endregion private void cbAutomatic_CheckedChanged(object sender, EventArgs e)
{
if (cbAutomatic.Checked)
{
cbRememberPwd.Checked = true;
return;
}
}
#endregion

最新文章

  1. HTTP的长连接和短连接
  2. 移动端Web适配的两种做法思路总结
  3. MySQL数据库命名及设计规范
  4. ZKM混淆工具
  5. Erlang 程序引发共享内存 bug 的一个例子
  6. oracle 笔记
  7. Dubbo扩展点加载机制
  8. Java中list&lt;Object&gt;集合去重实例
  9. 在OC和Swift中使用IBDesignable/IBInspectable
  10. js中对象相关
  11. swoole 弹幕系统
  12. iOS开发之文件(分段)下载
  13. 201521123068《Java程序设计》第1周学习总结
  14. 2017-06-24(chgrp umask alias unalias)
  15. Cocos Creator—定制H5游戏首页loading界面
  16. hive 使用反射函数
  17. new/new[]和delete/delete[]是如何分配空间以及释放空间的
  18. redis 3.2.3的源码安装
  19. 【Python】打印object对象
  20. mysql limit 优化

热门文章

  1. react高阶组件
  2. Java的Finalizer引发的内存溢出
  3. html/css/js-如何利用jq来更改属性的值和获取属性的值
  4. 03-封装Response响应
  5. 如何在idea里面新建一个maven项目,然后在这个maven项目里创建多个子模块
  6. 小程序打开pdf
  7. 6-安装hbase
  8. [UnityAPI]DataUtility类
  9. Eclipse关于怎么调出web project
  10. 【转】完整精确导入Kernel与Uboot参与编译了的代码到Source Insight,Understand, SlickEdit