Advertisement
Guest User

Untitled

a guest
Nov 30th, 2016
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.11 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Web;
  5. using System.Web.UI;
  6. using System.Web.UI.WebControls;
  7. using System.Configuration;
  8. using System.Data.SqlClient;
  9.  
  10. public partial class _Default : System.Web.UI.Page
  11. {
  12. protected void Page_Load(object sender, EventArgs e)
  13. {
  14.  
  15. }
  16.  
  17.  
  18.  
  19. protected void btnLogin_Click(object sender, EventArgs e)
  20.  
  21. {
  22. //SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["11horton.d@thestudio-liverpool.netConnectionString"].ConnectionString);
  23. //conn.Open();
  24. ////create the query to get the users login they've entered
  25. //string queryTemplate = "SELECT * FROM [11horton.d@thestudio-liverpool.net].[dbo].[FasthostsTable] where Username = '{0}' and Password = '{1}'";
  26. //string insertQuery = string.Format(queryTemplate, txtLoginUsername, txtLoginPassword);
  27.  
  28. ////set the command and set a reader using the command
  29. //SqlCommand com = new SqlCommand(insertQuery, conn);
  30. //SqlDataReader reader = com.ExecuteReader();
  31.  
  32. ////check if the user exists
  33. //if (reader.HasRows)
  34. //{
  35. // Response.Write("User Logged in");
  36. // Response.Redirect("UserManagement.aspx");
  37. //}
  38. //conn.Close();
  39.  
  40. try
  41. {
  42. //Create the connection string
  43. SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["11horton.d@thestudio-liverpool.netConnectionString"].ConnectionString);
  44. conn.Open();
  45.  
  46. //Check to see if the username already exists
  47. string checkuser = "select count(*) from fasthostsTable where UserName ='" + txtLoginUsername.Text + "'";
  48.  
  49. //Pass my query with two queries
  50. SqlCommand com = new SqlCommand(checkuser, conn);
  51.  
  52. //
  53. int temp = Convert.ToInt32(com.ExecuteScalar().ToString());
  54. conn.Close();
  55.  
  56.  
  57. // If user already exists, then show the following message
  58. if (temp == 1)
  59. {
  60. conn.Open();
  61. string checkPasswordQuery = "SELECT password FROM fasthostsTable WHERE UserName='" + txtLoginUsername.Text + "'";
  62. SqlCommand passwordComm = new SqlCommand(checkPasswordQuery, conn);
  63. string password = passwordComm.ExecuteScalar().ToString().Replace(" ", "");
  64.  
  65. if (password == txtLoginPassword.Text)
  66. {
  67. Session["new"] = txtLoginUsername.Text;
  68.  
  69. //MessageBox.Show("Password is correct");
  70. Response.Write("Password is correct!");
  71. Response.Redirect("UserManagement.aspx");
  72.  
  73. }
  74. else
  75. {
  76. Response.Write("Password is NOT correct!");
  77. }
  78.  
  79. }
  80. else
  81. {
  82. Response.Write("Username is incorrect");
  83. }
  84.  
  85. }
  86. catch (Exception ex)
  87. {
  88. Response.Write("Error:" + ex.ToString());
  89. }
  90. }
  91.  
  92. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement