Guest User

Untitled

a guest
Sep 20th, 2018
43
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.22 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.IO;
  7. using System.Linq;
  8. using System.Text;
  9. using System.Threading;
  10. using System.Threading.Tasks;
  11. using System.Windows.Forms;
  12. using TestAutoLoginAndRememberMe.Properties;
  13.  
  14. namespace TestAutoLoginAndRememberMe
  15. {
  16.     public partial class Form1 : Form
  17.     {
  18.         public static void ShowForm1()
  19.         {
  20.  
  21.         }
  22.         public Form1()
  23.         {
  24.             InitializeComponent();
  25.            
  26.         }
  27.  
  28.         private void startupSetup()
  29.         {
  30.             textBox1.Text = Settings.Default.userName;
  31.             textBox2.Text = Settings.Default.password;
  32.             checkBox1.Checked = Settings.Default.rememberMe;
  33.             checkBox2.Checked = Settings.Default.autoSignIn;
  34.         }
  35.  
  36.         private void button1_Click(object sender, EventArgs e)
  37.         {
  38.             //if login is ok
  39.             login();
  40.             startupSetup();
  41.         }
  42.  
  43.         private void login()
  44.         {
  45.             setupLoginOptions();
  46.             Form2 f2 = new Form2();
  47.             f2.form1 = this;
  48.             f2.Show();
  49.             Hide();
  50.         }
  51.  
  52.         private void setupLoginOptions()
  53.         {
  54.             Settings.Default.rememberMe = (checkBox1.Checked) ? true : false;
  55.             Settings.Default.autoSignIn = (checkBox2.Checked) ? true : false;
  56.             if(Settings.Default.autoSignIn)
  57.             {
  58.                 Settings.Default.userName = textBox1.Text;
  59.                 Settings.Default.password = textBox2.Text;
  60.             }
  61.             else if(Settings.Default.rememberMe)
  62.             {
  63.                 Settings.Default.userName = textBox1.Text;
  64.                 Settings.Default.password = "";
  65.             }
  66.             else
  67.             {
  68.                 Settings.Default.userName = "";
  69.                 Settings.Default.password = "";
  70.             }
  71.             Settings.Default.Save();
  72.                
  73.         }
  74.  
  75.         private void Form1_Shown(object sender, EventArgs e)
  76.         {
  77.             startupSetup();
  78.             if (checkBox2.Checked && textBox1.TextLength > 0 && textBox2.TextLength > 0)
  79.                 login();
  80.         }
  81.     }
  82. }
Add Comment
Please, Sign In to add comment