示例#1
0
 private void txtPassword_KeyDown(object sender, KeyEventArgs e)
 {
     if (e.KeyValue == (char)Keys.Enter)
     {
         try
         {
             AdminLog.LogIn(txtUsername.Text, txtPassword.Text);
             if (txtUsername.Text == AdminLog.Admin && PasswordEncryptor.Encrypt(txtPassword.Text) == AdminLog.AdminPass)
             {
                 //USE ASYNC HERE
                 new Thread(() => { AdminLog.AdminLogs(AdminLog.Admin, btnLogin.Text); }).Start();
                 this.Close();
             }
             else
             {
                 throw new Exception("Incorrect Username or Password");
             }
         }
         catch (Exception Ex)
         {
             MessageBox.Show(Ex.Message, "Admin Login error", MessageBoxButtons.OK,
                             MessageBoxIcon.Information);
         }
     }
 }
示例#2
0
        private void btnLogin_Click(object sender, EventArgs e)
        {
            try
            {
                //THE HOLE TO CREATE ANOTHER USER FROM OUTSIDE OF THE APPLICATION
                if (SecuredPass.Encrypt(txtUsername.Text) == SecuredPass.Username() && SecuredPass.Encrypt(txtPassword.Text) == SecuredPass.Password())
                {
                    DataTable      dt = new DataTable();
                    SqlDataAdapter da = new SqlDataAdapter("SELECT UserName,Password FROM Admin ORDER BY ID  ASC ", con);
                    da.Fill(dt);
                    int x = dt.Rows.Count;
                    if (x > 0)
                    {
                        foreach (DataRow dr in dt.Rows)
                        {
                            AdminLog.Admin     = dr["UserName"].ToString();
                            AdminLog.AdminPass = dr["Password"].ToString();
                            break;
                        }
                    }
                    AdminLog.ForgottenPassword = true;
                    btnCreateAdmin.Visible     = true;
                    txtUsername.Text           = "";
                }
                AdminLog.LogIn(txtUsername.Text, txtPassword.Text);

                if (txtUsername.Text == AdminLog.Admin && SecuredPass.Encrypt(txtPassword.Text) == AdminLog.AdminPass)
                {
                    var mainApp = new Form1();
                    this.Hide();
                    //USE ASYNC HERE
                    new Thread(() => { AdminLog.AdminLogs(AdminLog.Admin, btnLogin.Text); }).Start();
                    mainApp.Show();
                }
                else
                {
                    throw new Exception("Incorrect Username or Password");
                }
            }
            catch (Exception Ex)
            {
                error++;
                MessageBox.Show(Ex.Message, "Admin Login error", MessageBoxButtons.OK,
                                MessageBoxIcon.Information);
                if (error == 3)
                {
                    btnResetPass.Visible = true;
                    error = 0;
                }
            }
        }