Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Web;
- using System.Web.UI;
- using System.Web.UI.WebControls;
- using System.Configuration;
- using System.Data.SqlClient;
- public partial class _Default : System.Web.UI.Page
- {
- protected void Page_Load(object sender, EventArgs e)
- {
- }
- protected void btnLogin_Click(object sender, EventArgs e)
- {
- //SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["11horton.d@thestudio-liverpool.netConnectionString"].ConnectionString);
- //conn.Open();
- ////create the query to get the users login they've entered
- //string queryTemplate = "SELECT * FROM [11horton.d@thestudio-liverpool.net].[dbo].[FasthostsTable] where Username = '{0}' and Password = '{1}'";
- //string insertQuery = string.Format(queryTemplate, txtLoginUsername, txtLoginPassword);
- ////set the command and set a reader using the command
- //SqlCommand com = new SqlCommand(insertQuery, conn);
- //SqlDataReader reader = com.ExecuteReader();
- ////check if the user exists
- //if (reader.HasRows)
- //{
- // Response.Write("User Logged in");
- // Response.Redirect("UserManagement.aspx");
- //}
- //conn.Close();
- try
- {
- //Create the connection string
- SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["11horton.d@thestudio-liverpool.netConnectionString"].ConnectionString);
- conn.Open();
- //Check to see if the username already exists
- string checkuser = "select count(*) from fasthostsTable where UserName ='" + txtLoginUsername.Text + "'";
- //Pass my query with two queries
- SqlCommand com = new SqlCommand(checkuser, conn);
- //
- int temp = Convert.ToInt32(com.ExecuteScalar().ToString());
- conn.Close();
- // If user already exists, then show the following message
- if (temp == 1)
- {
- conn.Open();
- string checkPasswordQuery = "SELECT password FROM fasthostsTable WHERE UserName='" + txtLoginUsername.Text + "'";
- SqlCommand passwordComm = new SqlCommand(checkPasswordQuery, conn);
- string password = passwordComm.ExecuteScalar().ToString().Replace(" ", "");
- if (password == txtLoginPassword.Text)
- {
- Session["new"] = txtLoginUsername.Text;
- //MessageBox.Show("Password is correct");
- Response.Write("Password is correct!");
- Response.Redirect("UserManagement.aspx");
- }
- else
- {
- Response.Write("Password is NOT correct!");
- }
- }
- else
- {
- Response.Write("Username is incorrect");
- }
- }
- catch (Exception ex)
- {
- Response.Write("Error:" + ex.ToString());
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement