private void btnSignIn_Click(object sender, EventArgs e)
        {
            //initializing variables
            textUsername = "";
            textPassword = "";

            Encrypter encrypter = new Encrypter();

            textUsername = txtUsername.Text;
            //if password field is not empty then only encrypt it. Else leave it empty
            if (!string.IsNullOrEmpty(txtPassword.Text))
            {
                textPassword = encrypter.MD5Hash(txtPassword.Text);
            }

            //checking if any field is empty
            validateIfAnyFieldIsEmpty();
            if (!isFormValidationOk)
            {
                return;
            }                                //if form is not validated, dont execute futher lines of code

            //getting username and password from database
            if (!getDataFromDatabase())
            {
                return;
            }

            //Check if password is correct
            if (password.Equals(textPassword))
            {
                if (status.Equals("active"))
                {
                    openUserDashboard();
                }
                else
                {
                    MessageBox.Show("Your Account is INACTIVE, so please contact Administrator.");
                }
            }
            //show invalid password error
            else
            {
                MessageBox.Show("Your Password doesn't match.");
            }
        }
Example #2
0
        private void btnSignUp_Click(object sender, EventArgs e)
        {
            //initializing variables
            textUsername         = "";
            textPassword         = "";
            textConfirmPassoword = "";
            comboType            = "";

            textUsername         = txtUsername.Text;
            textPassword         = txtPassword.Text;
            textConfirmPassoword = txtConfirmPassword.Text;
            comboType            = cboType.Text;

            validateForm();
            if (!isFormValidationOk)
            {
                return;
            }
            if (checkIfUserAlreadyExist())
            {
                errorProvider1.SetError(txtUsername, null);
                errorProvider1.SetError(txtUsername, "User Already Registered,Please Enter New Username");
                txtUsername.Focus();
                return;
            }

            Encrypter encrypter = new Encrypter();
            String    conPass   = encrypter.MD5Hash(txtPassword.Text);

            try {
                dbConn.executeQuery("INSERT INTO userdetails (userid, username, password, type, status) VALUES " +
                                    "(NULL, '" + textUsername + "','" + conPass + "', '" + comboType.ToLower() + "','active');");
                MessageBox.Show("A New " + cboType.SelectedItem.ToString().ToUpper() + " has been Registered");
                txtConfirmPassword.Clear();
                txtPassword.Clear();
                txtUsername.Clear();
            }
            catch (Exception ex) { MessageBox.Show("" + ex.StackTrace); }
        }