예제 #1
0
        public void validateLogin(loginModel Obj)
        {
            try
            {
                dataAdapterObj = new SqlDataAdapter();
                selectCommand  = new SqlCommand();
                parameterObj   = new SqlParameter("@Password", Obj.Password);
                selectCommand.Parameters.Add(parameterObj);

                parameterObj1 = new SqlParameter("@Username", Obj.UserName);
                selectCommand.Parameters.Add(parameterObj1);
                selectCommand.CommandText    = "select count(UserName) from LoginCredentials where UserName=@Username and Password=@Password";
                selectCommand.Connection     = connectionObj;
                dataAdapterObj.SelectCommand = selectCommand;
                dataSetObj = new DataSet();
                dataAdapterObj.Fill(dataSetObj);


                var LoginStatus = (int)dataSetObj.Tables[0].Rows[0][0];
                if (LoginStatus <= 0)
                {
                    throw new LoginFailureException("Incorrect Password... Please try again");
                }
            }
            catch (LoginFailureException e)
            {
                throw new LoginFailureException(e.Message);
            }

            catch (Exception e)
            {
                throw new LoginFailureException("Select  a valid user name please dont enter");
            }
        }
예제 #2
0
        private void Button1_Click(object sender, EventArgs e) // Login Button
        {
            menuForm MenuObj = new menuForm();

            try
            {
                loginModel LoginObj = new loginModel(comboBox1.SelectedValue.ToString(), textBox1.Text);
                ObjLogin.validateLogin(LoginObj);
                textBox1.Text = "";
                this.Visible  = false;
                DialogResult dr = MenuObj.ShowDialog(this);
                this.Visible = true;
            }
            catch (LoginFailureException s)
            {
                MessageBox.Show(s.Message);
            }
        }