zoukankan      html  css  js  c++  java
  • c/s项目记住账号密码功能

     
    1.login.cs中的一开始加载页面
    //从注册表中读取 是否保存了用户名密码 自动启动配置 string RegeditKey = "PMSApp"; RegistryKey location = Registry.LocalMachine; RegistryKey soft = location.OpenSubKey("SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall", false);//可写 RegistryKey myPass = soft.OpenSubKey(RegeditKey, false); try { string banben = myPass.GetValue("DisplayVersion").ToString(); lbbanben.Text = "版本号 : " + banben; } catch (Exception ex) { //MessageBox.Show(ex.Message); } try { string s1 = myPass.GetValue("s1").ToString();//s1账号 string s2 = myPass.GetValue("s2").ToString();//s2密码 bool ifSave = Convert.ToBoolean(myPass.GetValue("s3"));//s3判断状态,是否需要启动改功能 checkBox1.IsChecked = ifSave; if (ifSave) { txtAdminPassword.Password = "";//我只需要记住账号所以这个地方可以忽略 txtAdminName.Text = s1; } else { txtAdminPassword.Password = ""; txtAdminName.Text = ""; } // ifFistIn = false; //程序已启动完毕,可以执行注册表相关动作 } catch (Exception ex) { //MessageBox.Show(ex.Message); } 2.记住账号按钮 //记住账号 private void checkBox1_Click(object sender, RoutedEventArgs e) { if ((sender as CheckBox).IsChecked == true) { string RegeditKey = "PMSApp"; RegistryKey location = Registry.LocalMachine; RegistryKey soft = location.OpenSubKey("SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall", true);//可写 RegistryKey myPass = soft.CreateSubKey(RegeditKey); myPass.SetValue("s1", txtAdminName.Text); myPass.SetValue("s2", txtAdminPassword.Password); myPass.SetValue("s3", checkBox1.IsChecked); soft.Close(); location.Close(); } else { string RegeditKey = "PMSApp"; RegistryKey location = Registry.LocalMachine; RegistryKey soft = location.OpenSubKey("SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall", true);//可写 RegistryKey myPass = soft.CreateSubKey(RegeditKey); myPass.SetValue("s1", txtAdminName.Text); myPass.SetValue("s2", txtAdminPassword.Password); myPass.SetValue("s3", checkBox1.IsChecked); soft.Close(); location.Close(); } } 3.更换账户时,改变记住账号的状态 private void txtAdminName_TextChanged(object sender, TextChangedEventArgs e) { string s1 = ""; try { string RegeditKey = "PMSApp"; RegistryKey location = Registry.LocalMachine; RegistryKey soft = location.OpenSubKey("SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall", false);//可写 RegistryKey myPass = soft.OpenSubKey(RegeditKey, false); s1 = myPass.GetValue("s1").ToString(); if (txtAdminName.Text == s1) { checkBox1.IsChecked = true; } else { checkBox1.IsChecked = false; } } catch { } }
  • 相关阅读:
    CloudStack+KVM环境搭建(步骤很详细,说明ClockStack是用来管理虚拟机的)
    CloudStack和OpenStack该如何选择(如果准备选择OpenStack,请做好hack的准备。CloudStack的底层功能已经做的很完善了,更适合商用)
    NancyFx And ReactiveX
    Apache Kafka® is a distributed streaming platform
    C/C++配置
    Win10 专业版 Hyper-V 主机计算服务无法启动
    使用事件和 CQRS 重写 CRUD 系统
    使用Skywalking分布式链路追踪系统
    GraphQL&DSL&API网关
    TomatoLog 是一个基于 .NETCore 平台的产品。
  • 原文地址:https://www.cnblogs.com/wdd812674802/p/10947671.html
Copyright © 2011-2022 走看看