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.Data;
- using System.Data.SqlClient;
- using System.Security.Cryptography;
- using System.ComponentModel;
- using System.Text;
- public partial class Login : System.Web.UI.Page
- {
- protected void Page_Load(object sender, EventArgs e)
- {
- loginFail.Visible = false;
- emailFail.Visible = false;
- }
- protected void loginButton_Click(object sender, System.EventArgs e)
- {
- string IndvConnString = System.Configuration.ConfigurationManager.ConnectionStrings["SQLAzureConnection"].ConnectionString;
- SqlConnection IndvSignCon = new SqlConnection(IndvConnString);
- IndvSignCon.Open();
- SqlCommand cmd;
- SqlDataReader rdr;
- Type checking = this.GetType();
- string checklogin = "SELECT * FROM Customer";
- cmd = new SqlCommand(checklogin, IndvSignCon);
- rdr = cmd.ExecuteReader();
- while (rdr.Read() == true)
- {
- if (email_textbox.Text == "" || password_textbox.Text == "")
- {
- return;
- }
- else
- {
- if (email_textbox.Text == (string)rdr["cEmail"])
- {
- string usernameSTR = email_textbox.Text;
- string getUserIDStr = System.Configuration.ConfigurationManager.ConnectionStrings["SQLAzureConnection"].ConnectionString;
- SqlConnection getUserIDCon = new SqlConnection(getUserIDStr);
- SqlCommand getUserIdCMD;
- string userIdSTR = "SELECT cID FROM Customer WHERE cEmail = @UserName";
- getUserIdCMD = new SqlCommand(userIdSTR, getUserIDCon);
- getUserIdCMD.Parameters.AddWithValue("@UserName", SqlDbType.VarChar).Value = usernameSTR;
- getUserIDCon.Open();
- SqlDataReader getUserIdRDR = getUserIdCMD.ExecuteReader();
- while (getUserIdRDR.Read() == true)
- {
- int userIDInt = (int)getUserIdRDR["cID"];
- string MatchHashStr = System.Configuration.ConfigurationManager.ConnectionStrings["SQLAzureConnection"].ConnectionString;
- SqlConnection MatchHashCON = new SqlConnection(MatchHashStr);
- SqlCommand MatchHashCMD;
- //Compare HashValue
- string CompareHashStr = null;
- byte[] compareSource;
- byte[] compareHash;
- CompareHashStr = password_textbox.Text;
- compareSource = ASCIIEncoding.ASCII.GetBytes(CompareHashStr);
- compareHash = new MD5CryptoServiceProvider().ComputeHash(compareSource);
- string MatchHashSQLStr = "SELECT cEmail FROM Customer WHERE cID = @CustomerID AND cPassword = @CompareHash";
- MatchHashCMD = new SqlCommand(MatchHashSQLStr, MatchHashCON);
- MatchHashCMD.Parameters.AddWithValue("@CustomerID", SqlDbType.Int).Value = userIDInt;
- MatchHashCMD.Parameters.Add("@CompareHash", SqlDbType.VarBinary, 16).Value = compareHash;
- MatchHashCON.Open();
- SqlDataReader MatchHashRDR = MatchHashCMD.ExecuteReader();
- while (MatchHashRDR.Read() == true)
- {
- string exstUserNameStr = (string)rdr["cEmail"].ToString() ;
- if (exstUserNameStr == usernameSTR)
- {
- Session["sFlag"] = "T"; // sFlag = "T" means user has logged in
- Session["sName"] = rdr["cFullName"];
- Session["sAddress"] = rdr["cAddress"];
- Session["sEmail"] = rdr["cEmail"];
- Session["sMobile"] = rdr["cHp"];
- Session["sCompany"] = rdr["cCompanyName"];
- Session["sCustomerID"] = rdr["cID"].ToString(); //ToString() Convert Integer to String
- string strCustomerId = (string)Session["sCustomerID"];
- DataRoutines DRObject = new DataRoutines();
- DRObject.CreateRecs(strCustomerId);
- IndvSignCon.Close();
- getUserIDCon.Close();
- MatchHashCON.Close();
- Response.Redirect("MyAccount.aspx");
- }
- else
- {
- Session["sFlag"] = "F";
- Session["sName"] = "";
- Session["sCustomerID"] = "";
- loginFail.Visible = true;
- }
- }
- MatchHashCON.Close();
- }
- getUserIDCon.Close();
- }
- else
- {
- emailFail.Visible = true;
- }
- }
- }
- IndvSignCon.Close();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment