示例#1
0
        private void button1_Click(object sender, EventArgs e)
        {
            try
            {
                if (textBox2.Text == textBox3.Text)
                {
                    if (PasswordPolicy.IsValid(textBox2.Text))
                    {
                        string passWord = textBox2.Text;
                        string userName = textBox1.Text;
                        string userType = textBox4.Text;

                        if (userType.Equals("admin", StringComparison.InvariantCultureIgnoreCase))
                        {
                            frmAuth objFrmAuth = new frmAuth(userName, passWord);
                            this.Hide();
                            objFrmAuth.Show();
                        }
                        else if (userType.Equals("faculty", StringComparison.InvariantCultureIgnoreCase))
                        {
                            sqlConn.Open();

                            SqlCommand cmd = new SqlCommand("insert into tbl_Login(username, password, login_type) values ('" + userName + "','" + passWord + "', 2)", sqlConn);
                            cmd.ExecuteScalar();

                            MessageBox.Show("User Created!!");

                            frmLogin objFrmLogin = new frmLogin();
                            this.Hide();
                            objFrmLogin.Show();

                            sqlConn.Close();
                        }
                        else if (userType.Equals("student", StringComparison.InvariantCultureIgnoreCase))
                        {
                            sqlConn.Open();

                            SqlCommand cmd = new SqlCommand(@"insert into tbl_Login(username, password, login_type) values ('" + userName + "','" + passWord + "', 3)", sqlConn);
                            cmd.ExecuteScalar();

                            MessageBox.Show("User Created!!");

                            frmLogin objFrmLogin = new frmLogin();
                            this.Hide();
                            objFrmLogin.Show();

                            sqlConn.Close();
                        }
                        else
                        {
                            MessageBox.Show("Invalid User Type");
                            textBox1.Clear();
                            textBox2.Clear();
                            textBox3.Clear();
                            textBox4.Clear();
                        }
                    }
                    else
                    {
                        MessageBox.Show("Password doesn't meet requirements.");
                        textBox1.Clear();
                        textBox2.Clear();
                        textBox3.Clear();
                        textBox4.Clear();
                    }
                }
                else
                {
                    MessageBox.Show("Passwords must match.");
                    textBox1.Clear();
                    textBox2.Clear();
                    textBox3.Clear();
                    textBox4.Clear();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("An error occurred but your application did not crash.  Please contact a system admin if this continues.");
                string filePath = @"C:\Users\Error.txt";

                using (StreamWriter writer = new StreamWriter(filePath, true))
                {
                    writer.WriteLine("-----------------------------------------------------------------------------");
                    writer.WriteLine("Date : " + DateTime.Now.ToString());
                    writer.WriteLine();

                    while (ex != null)
                    {
                        writer.WriteLine(ex.GetType().FullName);
                        writer.WriteLine("Message : " + ex.Message);
                        writer.WriteLine("StackTrace : " + ex.StackTrace);
                    }
                }
            }
        }
示例#2
0
        private void btnLogin_Click(object sender, EventArgs e)
        {
            try
            {
                SqlCommand     cmd  = new SqlCommand("select username,password from tbl_Login where username='******'and password='******'", sqlConn);
                SqlDataAdapter sda  = new SqlDataAdapter(cmd);
                DataTable      dtbl = new DataTable();
                sda.Fill(dtbl);

                if (dtbl.Rows.Count > 0)
                {
                    sqlConn.Open();

                    SqlCommand cmd2 = new SqlCommand("select login_type from tbl_Login where username='******' and password='******'", sqlConn);

                    // Get result
                    int result = ((int)cmd2.ExecuteScalar());

                    // Admin Dashboard
                    if (result == 1)
                    {
                        SqlCommand cmd3 = new SqlCommand("insert into tbl_Login(username, password, login_type) values ('" + this.userName + "','" + this.passWord + "', 1)", sqlConn);
                        cmd3.ExecuteScalar();

                        MessageBox.Show("User Created!!");

                        frmLogin objFrmLogin = new frmLogin();
                        this.Hide();
                        objFrmLogin.Show();
                    }
                    else
                    {
                        MessageBox.Show("You need Admin authorization in order to create a new Admin User.");
                    }
                }
                else
                {
                    MessageBox.Show("Check your username or password.");
                }
                sqlConn.Close();
            }
            catch (Exception ex)
            {
                MessageBox.Show("An error occurred but your application did not crash.  Please contact a system admin if this continues.");
                string filePath = @"C:\Users\Error.txt";

                using (StreamWriter writer = new StreamWriter(filePath, true))
                {
                    writer.WriteLine("-----------------------------------------------------------------------------");
                    writer.WriteLine("Date : " + DateTime.Now.ToString());
                    writer.WriteLine();

                    while (ex != null)
                    {
                        writer.WriteLine(ex.GetType().FullName);
                        writer.WriteLine("Message : " + ex.Message);
                        writer.WriteLine("StackTrace : " + ex.StackTrace);
                    }
                }
            }
        }