c/s项目记住账号密码功能
生活随笔
收集整理的這篇文章主要介紹了
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{ }}
?
轉載于:https://www.cnblogs.com/wdd812674802/p/10947671.html
總結
以上是生活随笔為你收集整理的c/s项目记住账号密码功能的全部內容,希望文章能夠幫你解決所遇到的問題。