Click here to Skip to main content
15,886,873 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
TimeSpan start = new TimeSpan(9, 0, 0);
                    TimeSpan end = new TimeSpan(12, 0, 0);
                    TimeSpan now = DateTime.Now.TimeOfDay;
                    if ((now > start) && (now < end))
                    {
                        
                    }


What I have tried:

private void btnLogin_Click(object sender, RoutedEventArgs e)
      {
          if (txtUsername.Text == "")
          {
              MessageBox.Show("Please enter Username", "Fill Field", MessageBoxButton.OK, MessageBoxImage.Information);
              txtUsername.Focus();
          }
          else if (txtPassword.Password.ToString() == "")
          {
              MessageBox.Show("Please enter Password", "Fill Field", MessageBoxButton.OK, MessageBoxImage.Information);
              txtPassword.Focus();
          }
          try
          {
              //    dsb dsd = new dsb();
              //    dsd.Show();
              //    this.Close();
              string uname, pwd;
              uname = txtUsername.Text;
              pwd = txtPassword.Password;
              DataSet ds = Globalvariables.Globals.select("select employee_id,privilege from add_user where username= '" + uname + "',password= '" + pwd + "'");
              //DataRow drow;
              //string drowpass = "";
              if (ds.Tables[0].Rows[0][0].ToString() == null || ds.Tables[0].Rows[0][0].ToString() == string.Empty)
              {
                  Globals.set_sclose_employee_id(ds.Tables[0].Rows[0][0].ToString());
                  int y = Convert.ToInt32(ds.Tables[0].Rows[0][0].ToString());
                  Globals.SetGlobalInt(y);
                  int z;
                  if (ds.Tables[0].Rows[0][0].ToString() == null || ds.Tables[0].Rows[0][0].ToString() == string.Empty)
                  {
                      z = Convert.ToInt32(ds.Tables[0].Rows[0][0].ToString());
                  }
                  else
                  {
                      z = 0;
                  }
                  TimeSpan start = new TimeSpan(9, 0, 0);
                  TimeSpan end = new TimeSpan(12, 0, 0);
                  TimeSpan now = DateTime.Now.TimeOfDay;
                  if ((now > start) && (now < end))
                  {

                  }
Posted
Comments
Richard Deeming 19-Oct-22 7:27am    
DataSet ds = Globalvariables.Globals.select("select employee_id,privilege from add_user where username= '" + uname + "',password= '" + pwd + "'");

Your code is vulnerable to SQL Injection[^]. NEVER use string concatenation/interpolation to build a SQL query. ALWAYS use a parameterized query.
Richard Deeming 19-Oct-22 7:27am    
You are storing your users' passwords in plain text. Don't do that!
Secure Password Authentication Explained Simply[^]
Richard Deeming 19-Oct-22 7:28am    
And your query has a syntax error, so it will only work if someone deliberately tries to exploit the SQL Injection vulnerability - eg: by entering a username of ' or 1 = 1;--.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900