Re: New to C# - DB question

Tech-Archive recommends: Fix windows errors by optimizing your registry



As for the security concern, I switched the login to use SQL Server
auth like this:

private void btnSubmit_Click(object sender, EventArgs e)
{
if (this.txtPassWd.Text.Length < 1 ||
this.txtUserID.Text.Length < 1)
{
MessageBox.Show("You MUST fill both fields in!");
return;
}

SqlConnection Conn;
SqlDataReader reader = null;

Conn = new SqlConnection("user id=" + this.txtUserID.Text +
";" +
"password=" +
this.txtPassWd.Text + ";" +
"server=MIKIE\\SQLEXPRESS;" +
"database=Media Manager;" +
"connection timeout=30");
try
{
Conn.Open();
}
catch
{
MessageBox.Show("Login Failed for user: " +
this.txtUserID.Text);
return;
}

try
{
SqlCommand cmd = new SqlCommand("spGetAuthority",
Conn);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.Add(new SqlParameter("@UserName",
this.txtUserID.Text));
reader = cmd.ExecuteReader();

if (reader.HasRows)
{
// Login is good here
reader.Read();
oLocalUser.iAuthority = reader.GetInt32(0);
oLocalUser.bLoggedIn = true;
MessageBox.Show("Login is good for User: " +
this.txtUserID.Text + " Auth code = " +
oLocalUser.iAuthority.ToString());

}
else
{
MessageBox.Show("Login Failed");
}
}
finally
{
reader.Close();
Conn.Close();

}

}

.



Relevant Pages

  • Login of different user after Logout
    ... is accepted I redirect the user using ... private void btnLogin_Click(object sender, System.EventArgs e) ... login page to show up again. ...
    (microsoft.public.dotnet.framework.aspnet)
  • ReDirect - Please Help
    ... protected by secutity and allow anyone to access them? ... >On the login page that displays I have private void ... >LinkButton1_Click(object sender, System.EventArgs e) ... >Using debug I see that both buttons just re-load the Login ...
    (microsoft.public.vsnet.general)
  • forms authentication question
    ... I am using Forms authentication for the first time, ... private void Page_Load(object sender, System.EventArgs e) ... Default_new_user.aspx is used to login users that don't have a cookie on ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: Forms authentication and session expiration
    ... Protected Sub Application_AcquireRequestState(ByVal sender As Object, ... After the user has been signout we try to access the same page and if thats ok, ie the page is also ment for anonymous access, that page is displayed and not the login page. ... its not like the web server restarts too much ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: ReDirect - Please Help
    ... keep sending people back to the login page. ... Ken Dopierala Jr. ... > private void LinkButton1_Click(object sender, ... > Msg.Text = "ReDirecting to Home.aspx"; ...
    (microsoft.public.dotnet.general)