diff --git a/AspNetFrameworkMVC/AspNetFrameworkMVC/AspNetFrameworkMVC.csproj b/AspNetFrameworkMVC/AspNetFrameworkMVC/AspNetFrameworkMVC.csproj index bd459ab..4ab990e 100644 --- a/AspNetFrameworkMVC/AspNetFrameworkMVC/AspNetFrameworkMVC.csproj +++ b/AspNetFrameworkMVC/AspNetFrameworkMVC/AspNetFrameworkMVC.csproj @@ -124,6 +124,7 @@ Global.asax + @@ -180,7 +181,6 @@ - diff --git a/AspNetFrameworkMVC/AspNetFrameworkMVC/Controllers/HomeController.cs b/AspNetFrameworkMVC/AspNetFrameworkMVC/Controllers/HomeController.cs index 440b9b5..b05c14b 100644 --- a/AspNetFrameworkMVC/AspNetFrameworkMVC/Controllers/HomeController.cs +++ b/AspNetFrameworkMVC/AspNetFrameworkMVC/Controllers/HomeController.cs @@ -1,4 +1,5 @@ -using System; +using AspNetFrameworkMVC.Models; +using System; using System.Collections.Generic; using System.IO; using System.Linq; @@ -64,5 +65,15 @@ namespace AspNetFrameworkMVC.Controllers byte[] fileBytes = System.IO.File.ReadAllBytes(filePath); return File(fileBytes, System.Net.Mime.MediaTypeNames.Application.Zip, Path.GetFileName(filePath)); } + + public ActionResult CheckLogin() + { + string filename = Request.QueryString["username"]; + string password = Request.QueryString["password"]; + + bool success = LoginManager.CheckLogin(filename, password); + ViewBag.Success = success; + return View(); + } } } \ No newline at end of file diff --git a/AspNetFrameworkMVC/AspNetFrameworkMVC/Models/LoginManager.cs b/AspNetFrameworkMVC/AspNetFrameworkMVC/Models/LoginManager.cs new file mode 100644 index 0000000..bd1028a --- /dev/null +++ b/AspNetFrameworkMVC/AspNetFrameworkMVC/Models/LoginManager.cs @@ -0,0 +1,29 @@ +using System; +using System.Collections.Generic; +using System.Data.SqlClient; +using System.Linq; +using System.Web; +using System.Web.Configuration; + +namespace AspNetFrameworkMVC.Models +{ + public class LoginManager + { + public static bool CheckLogin(string username, string password) + { + string connString = WebConfigurationManager.ConnectionStrings["Default"].ConnectionString; + using (SqlConnection conn = new SqlConnection(connString)) + { + conn.Open(); + string qry = "SELECT * FROM Login WHERE Username = @user AND Password = @password"; + SqlCommand cmd = new SqlCommand(qry, conn); + cmd.Parameters.AddWithValue("@user", username); + cmd.Parameters.AddWithValue("@password", password); + object res = cmd.ExecuteScalar(); + + return res != null; + } + + } + } +} \ No newline at end of file diff --git a/AspNetFrameworkMVC/AspNetFrameworkMVC/Web.config b/AspNetFrameworkMVC/AspNetFrameworkMVC/Web.config index e91d705..5b27a8c 100644 --- a/AspNetFrameworkMVC/AspNetFrameworkMVC/Web.config +++ b/AspNetFrameworkMVC/AspNetFrameworkMVC/Web.config @@ -56,4 +56,7 @@ + + + \ No newline at end of file