private void frmChat_Load(object sender, EventArgs e) { lblInvLogin.Visible = false; //On Startup, check the resources directory for anything where a .usr file exists. //If a .usr file exists check for the term 'Preferred' //If found, login using that information string fName = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\" + System.Reflection.Assembly.GetExecutingAssembly().GetName().Name.ToString() + "\\resources\\"; //Check for UAC stored username / Password will be included by default. if (Properties.Settings.Default.UserName != string.Empty) { //Redundant file-check to confirm if user-file was made. If so; use stored function and file for less DB table poll. if (Directory.Exists(fName)) { //Get all files in folder if DB Exists. string[] fileEntries = Directory.GetFiles(fName); foreach (string filename in fileEntries) { if (processFile(filename)) { //If true; log in user using File as 'quick authentication' LoggedIn clientForm = new LoggedIn(); clientForm.Show(); //Hide the main-screen this.WindowState = FormWindowState.Minimized; this.ShowInTaskbar = false; } //End if } //End loop } //End if } //End if }
private void btnLogin_Click(object sender, EventArgs e) { this.btnLogin.BackgroundImage = new Bitmap(icons.buttonActive); string usrEmail = txtEmail.Text, usrPass = txtPass.Text; string sqlRetEmail = "", sqlRetPass = ""; try { if (usrEmail == null || usrPass == null || usrEmail == "" || usrPass == "") { //throw new Exception("No inputs detected."); }//End if List <SqlParameter> Parameters = new List <SqlParameter>(); Parameters.Add(new SqlParameter("Email", usrEmail)); Parameters.Add(new SqlParameter("Password", usrPass)); var sqlOut = DAL.ExecStoredProcedure("Login", Parameters); DataTable dt = sqlOut; foreach (DataRow row in sqlOut.Rows) { sqlRetEmail = row["Email"].ToString(); sqlRetPass = row["Password"].ToString(); }//End loop if (sqlRetEmail == usrEmail.ToString() && sqlRetPass == usrPass.ToString()) { if (chkRememberMe.Checked) { //Variables to store in Windows UAC for later user. Properties.Settings.Default.UserName = usrEmail; Properties.Settings.Default.Password = usrPass; Properties.Settings.Default.Save(); //Prepare two pre-encrypted strings for later use. string encryptedString = StringCipher.Encrypt(usrEmail, usrPass); string encryptedPass = StringCipher.Encrypt(usrPass, usrPass); string[] saveToFileLines = { encryptedString, encryptedPass, StringCipher.Encrypt("preferred", usrPass) }; //Look for AppData\Roaming folder. string fName = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\" + System.Reflection.Assembly.GetExecutingAssembly().GetName().Name.ToString() + "\\resources\\"; //MessageBox.Show(fName + usrEmail.ToString().Split('@')[0] + ".usr"); //Used for testing //Determine if file and directory exists. if (!File.Exists(@fName + usrEmail.ToString().Split('@')[0] + ".usr")) { //Does just the directory exist? if (!Directory.Exists(@fName)) { //Create if not. Directory.CreateDirectory(@fName); }//End If //Prepare and deliver directory. System.IO.File.WriteAllLines(fName + usrEmail.ToString().Split('@')[0] + ".usr", saveToFileLines); System.IO.File.Encrypt(fName + usrEmail.ToString().Split('@')[0] + ".usr"); }//End If } LoggedIn clientForm = new LoggedIn(); clientForm.Show(); this.Hide(); } //End If else { lblInvLogin.Text = "Invalid Login"; lblInvLogin.Visible = true; if (x == 2) { lblInvLogin.Text = "Invalid Login; Access has been locked for 5 minutes."; txtEmail.Enabled = false; txtPass.Enabled = false; btnLogin.Enabled = false; y = 0; timer1.Enabled = true; timer1.Start(); x = 0; } else { x++; } }//End if } catch (Exception ex) { //MessageBox.Show(ex.ToString()); } }//End button click function