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

  #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

C# Winform 登录中的忘记密码及自动登录的更多相关文章

  1. php中实现记住密码下次自动登录的例子

    这篇文章主要介绍了php中实现记住密码下次自动登录的例子,本文使用cookie实现记住密码和自动登录功能,需要的朋友可以参考下 做网站的时候经常会碰到要实现记住密码,下次自动登录,一周内免登陆,一个月 ...

  2. 基于localStorge开发登录模块的记住密码与自动登录

    前沿||我是乐于分享,善于交流的鸟窝 先做写一篇关于登录模块中记住密码与自动登录的模块.鸟窝微信:jkxx123321 关于这个模块功能模块的由来,这是鸟大大的处女秀,为什么这么说呢?一天在群里,一个 ...

  3. WinForm应用程序的开机自启、记住密码,自动登录的实现

    一.思路: 1.开机自启,自然是需要用到注册表,我们需要把程序添加到电脑的注册表中去 2.记住密码,自动登录,开机自启,在页面的呈现我们都使用复选框按钮来呈现 3.数据持久化,不能是数据库,可以是sq ...

  4. 64位 windows10,MYSQL8.0.13重置密码(忘记密码或者无法登录)

    上一节的MySQL的配置安装里,并没有用到配置文件my.ini.那在MYSQL8.0.13如何解决密码重置问题呢.我去网上搜了好多的资料都是改配置文件my.ini的,后来终于找到了一条命令:操作步骤如 ...

  5. 一个简单WPF登陆界面,包含记住密码,自动登录等功能,简洁美观

    简介:这是一个自己以前用WPF设计的登陆界面,属于一个实验性的界面窗体,如果用于产品还很有不足.但也是有一点学习价值.后台代码略有复杂,但基本上都有注释 分类,略有代码经验的一般都能看懂. 登陆界面外 ...

  6. Centos 解决SSH 免密码登录 以及Crontab制作定时SSH自动登录和关闭的脚本

    一.SSH免密码登录 假设要登录的机器为192.168.1.100,当前登录的机器为192.168.1.101. 首先在101的机器上生成密钥(如果已经生成可以跳过): $ ssh-keygen -t ...

  7. 数据加密实战之记住密码、自动登录和加密保存数据运用DES和MD5混合使用

    MD5的简介:MD5即Message-Digest Algorithm 5(信息-摘要算法5),用于确保信息传输完整一致.是计算机广泛使用的杂凑算法之一(又译摘要算法.哈希算法),主流编程语言普遍已有 ...

  8. cookie、session及实现记住密码,自动登录

    在登录帐号.密码框下,有三种帐号登录模式可供选择,用户可根据自己的具体情况选择其中一种适合自己的模式. 1.网吧模式:勾选网吧模式后,登录的帐号会在歪歪注销/退出的时候自动清除,不会留在登录框中,可以 ...

  9. Android 记住密码和自动登录界面的实现(SharedPreferences 的用法)

    原文:http://blog.csdn.net/liuyiming_/article/details/7704923 SharedPreferences介绍: SharedPreferences是An ...

随机推荐

  1. python之路——7

    王二学习python的笔记以及记录,如有雷同,那也没事,欢迎交流,wx:wyb199594 复习 1. 小数据池 int -5---256 str 特殊字符 *202. ASCII码 8位 1字节 - ...

  2. 石板地面 Base Shape

    软件:Substance Designer 2017.1.2 石板地面 Base Shape 效果见图一 图一:Base Shape (2D View) 首先使用Cells 1(Pattern)结点生 ...

  3. CRM 2016 及 CRM 365 更新地址

    CRM2016安装程序下载地址: https://www.microsoft.com/zh-cn/download/details.aspx?id=50372 CRM 365 更新地址: https: ...

  4. mybatis的typeHandler

    typeHandler作用: 1.传参时将javaType类型转换成jdbcType 2.结果集中ResultSet中取值时,jdbcType转换为javaType; 系统自定义的typeHandle ...

  5. 生产者-消费者(wait-notify实现)

    使用wait/notify来实现生产者消费者时能够达到在线程阻塞的效果,这样就不会出现轮询,然后浪费cpu时间的目的.代码如下:1. 状态类,表示是否已经生产: package com.demo; p ...

  6. py库:文本转为语音(pywin32、pyttsx)

    http://blog.csdn.net/marksinoberg/article/details/52137547 Python 文本转语音 文本转为语音(使用Speech API) 需要安装 py ...

  7. Laravel数据库操作 Eloquent ORM

    模型首先在App目录下建立student的文件夹 里面放上 Student.php 且需要继承基类Model //允许批量赋值的字段// protected $fillable = ['name',' ...

  8. kaggle首秀之intel癌症预测(续篇)

    之前写了这篇文章.现在把他搬到知乎live上了.书非借不能读也,因此搞了点小费用,如果你觉得贵,加我微信我给你发红包返回给你. 最近的空余时间拿去搞kaggle了, 好久没更新文章了.今天写写kagg ...

  9. Mac 笔记本 开发日记

    1.录屏,截图 Mac 自带录屏功能 command +control +o 2.复制当前应用,在启一个当前app窗口 command+n 3.快速回到桌面 command +f3 4.选中文件,复制 ...

  10. mac下安装cnpm淘宝镜像

    cnpm:官网 (事先已经安装了node,有npm)查看官网,提示安装需运行命令:npm install -g cnpm --registry=https://registry.npm.taobao. ...