Hi i've got a simple username and password entry on my webpage.
My login class works perfectly in Windows Form but not in my Web Application
Login class:
using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Data.SqlClient;
namespace assignmentForm
{
public class UserLogin
{
private SqlConnection connection = new SqlConnection();
public UserLogin()
{
///create sql connection
connection.ConnectionString = @"Data Source=localhost\sqlexpress;Initial Catalog=coffee;Integrated Security=True;Pooling=False";
connection.Open();
}
public Boolean Login(String username, String password)
{
SqlCommand cmd = new SqlCommand("SELECT * FROM [users] WHERE [username]='" + username + "' AND [password]='" + password + "'", connection);
SqlDataReader reader = cmd.ExecuteReader();
bool found = false;
if (reader.Read())
{
found = true;
}
reader.Close();
connection.Close();
return found;
}
}
}
namespace AsgWeb
{
public partial class login : System.Web.UI.Page
{
private UserLogin UserID;
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
UserID = new UserLogin();
if (UserID.Login(txtUsername.Text, txtPassword.Text))
{
Response.Redirect("coffeeLogin.aspx");
}
else
{
}
}
}
}
}
UserID = new UserLogin(); gives me an error saying it could not be found.