Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. A login problem

A login problem

Scheduled Pinned Locked Moved ASP.NET
helpcsharpasp-netdata-structurescryptography
9 Posts 5 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • F Offline
    F Offline
    Farhad Eft
    wrote on last edited by
    #1

    Hi Can anybody help me please. when i try to login in my asp.net 4 page with the following source code an error returns: DataTable dt = new DataTable(); DataSet ds = new DataSet(); SqlConnection sqlConn = new SqlConnection(ConfigurationManager.ConnectionStrings["SN11ConnectionString"].ConnectionString); SqlCommand sqlCmd = new SqlCommand("SELECT UserId FROM [Users] WHERE ([Email]=@Email AND [Password]=@Password", sqlConn); //Create the parameters SqlParameter paramEmail; paramEmail = new SqlParameter("@Email", SqlDbType.NVarChar, 25); paramEmail.Value = TextBoxLoginEmail.Text; sqlCmd.Parameters.Add(paramEmail); //Hash the password MD5CryptoServiceProvider md5Hasher = new MD5CryptoServiceProvider(); byte[] hashedBytes; UTF8Encoding encoder = new UTF8Encoding(); hashedBytes = md5Hasher.ComputeHash(encoder.GetBytes(TextBoxLoginPassword.Text)); SqlParameter paramPwd; paramPwd = new SqlParameter("@Password", SqlDbType.Binary, 16); paramPwd.Value = hashedBytes; sqlCmd.Parameters.Add(paramPwd); sqlConn.Open(); SqlDataAdapter sda = new SqlDataAdapter(sqlCmd); sda.Fill(ds); dt = ds.Tables[0]; Here is the error message that appears when i press the login button: Incorrect syntax near '@Password'. Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. Exception Details: System.Data.SqlClient.SqlException: Incorrect syntax near '@Password'. Source Error: Line 57: sqlConn.Open(); Line 58: SqlDataAdapter sda = new SqlDataAdapter(sqlCmd); Line 59: sda.Fill(ds); Line 60: dt = ds.Tables[0]; Line 61: } Thank you.

    V C L S 4 Replies Last reply
    0
    • F Farhad Eft

      Hi Can anybody help me please. when i try to login in my asp.net 4 page with the following source code an error returns: DataTable dt = new DataTable(); DataSet ds = new DataSet(); SqlConnection sqlConn = new SqlConnection(ConfigurationManager.ConnectionStrings["SN11ConnectionString"].ConnectionString); SqlCommand sqlCmd = new SqlCommand("SELECT UserId FROM [Users] WHERE ([Email]=@Email AND [Password]=@Password", sqlConn); //Create the parameters SqlParameter paramEmail; paramEmail = new SqlParameter("@Email", SqlDbType.NVarChar, 25); paramEmail.Value = TextBoxLoginEmail.Text; sqlCmd.Parameters.Add(paramEmail); //Hash the password MD5CryptoServiceProvider md5Hasher = new MD5CryptoServiceProvider(); byte[] hashedBytes; UTF8Encoding encoder = new UTF8Encoding(); hashedBytes = md5Hasher.ComputeHash(encoder.GetBytes(TextBoxLoginPassword.Text)); SqlParameter paramPwd; paramPwd = new SqlParameter("@Password", SqlDbType.Binary, 16); paramPwd.Value = hashedBytes; sqlCmd.Parameters.Add(paramPwd); sqlConn.Open(); SqlDataAdapter sda = new SqlDataAdapter(sqlCmd); sda.Fill(ds); dt = ds.Tables[0]; Here is the error message that appears when i press the login button: Incorrect syntax near '@Password'. Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. Exception Details: System.Data.SqlClient.SqlException: Incorrect syntax near '@Password'. Source Error: Line 57: sqlConn.Open(); Line 58: SqlDataAdapter sda = new SqlDataAdapter(sqlCmd); Line 59: sda.Fill(ds); Line 60: dt = ds.Tables[0]; Line 61: } Thank you.

      V Offline
      V Offline
      Venkatesh Mookkan
      wrote on last edited by
      #2

      Farhad Eft wrote:

      paramPwd = new SqlParameter("@Password", SqlDbType.Binary, 16);

      SqlDbType.Binary for Password? Please check the data type.

      Venkatesh Mookkan (My Recent Article: WPF Custom Control - FilterControl for ListBox/ListView)

      F 1 Reply Last reply
      0
      • F Farhad Eft

        Hi Can anybody help me please. when i try to login in my asp.net 4 page with the following source code an error returns: DataTable dt = new DataTable(); DataSet ds = new DataSet(); SqlConnection sqlConn = new SqlConnection(ConfigurationManager.ConnectionStrings["SN11ConnectionString"].ConnectionString); SqlCommand sqlCmd = new SqlCommand("SELECT UserId FROM [Users] WHERE ([Email]=@Email AND [Password]=@Password", sqlConn); //Create the parameters SqlParameter paramEmail; paramEmail = new SqlParameter("@Email", SqlDbType.NVarChar, 25); paramEmail.Value = TextBoxLoginEmail.Text; sqlCmd.Parameters.Add(paramEmail); //Hash the password MD5CryptoServiceProvider md5Hasher = new MD5CryptoServiceProvider(); byte[] hashedBytes; UTF8Encoding encoder = new UTF8Encoding(); hashedBytes = md5Hasher.ComputeHash(encoder.GetBytes(TextBoxLoginPassword.Text)); SqlParameter paramPwd; paramPwd = new SqlParameter("@Password", SqlDbType.Binary, 16); paramPwd.Value = hashedBytes; sqlCmd.Parameters.Add(paramPwd); sqlConn.Open(); SqlDataAdapter sda = new SqlDataAdapter(sqlCmd); sda.Fill(ds); dt = ds.Tables[0]; Here is the error message that appears when i press the login button: Incorrect syntax near '@Password'. Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. Exception Details: System.Data.SqlClient.SqlException: Incorrect syntax near '@Password'. Source Error: Line 57: sqlConn.Open(); Line 58: SqlDataAdapter sda = new SqlDataAdapter(sqlCmd); Line 59: sda.Fill(ds); Line 60: dt = ds.Tables[0]; Line 61: } Thank you.

        C Offline
        C Offline
        C Coudou
        wrote on last edited by
        #3

        new SqlCommand("SELECT UserId FROM [Users] WHERE ([Email]=@Email AND [Password]=@Password", sqlConn);

        u miss ")". check it.

        C# コードMicrosoft End User 2000-2008 「「「「「「「「「「「「「「「「「「「「「「「「「「「「 The best things in life are free 」」」」」」」」」」」」」」」」」」」」」」」」」」」」

        F 2 Replies Last reply
        0
        • C C Coudou

          new SqlCommand("SELECT UserId FROM [Users] WHERE ([Email]=@Email AND [Password]=@Password", sqlConn);

          u miss ")". check it.

          C# コードMicrosoft End User 2000-2008 「「「「「「「「「「「「「「「「「「「「「「「「「「「「 The best things in life are free 」」」」」」」」」」」」」」」」」」」」」」」」」」」」

          F Offline
          F Offline
          Farhad Eft
          wrote on last edited by
          #4

          where did i miss it? i can't see it!

          1 Reply Last reply
          0
          • V Venkatesh Mookkan

            Farhad Eft wrote:

            paramPwd = new SqlParameter("@Password", SqlDbType.Binary, 16);

            SqlDbType.Binary for Password? Please check the data type.

            Venkatesh Mookkan (My Recent Article: WPF Custom Control - FilterControl for ListBox/ListView)

            F Offline
            F Offline
            Farhad Eft
            wrote on last edited by
            #5

            yeah it's binary because I'd like to store and retrieve the encrypted edition.

            1 Reply Last reply
            0
            • C C Coudou

              new SqlCommand("SELECT UserId FROM [Users] WHERE ([Email]=@Email AND [Password]=@Password", sqlConn);

              u miss ")". check it.

              C# コードMicrosoft End User 2000-2008 「「「「「「「「「「「「「「「「「「「「「「「「「「「「 The best things in life are free 」」」」」」」」」」」」」」」」」」」」」」」」」」」」

              F Offline
              F Offline
              Farhad Eft
              wrote on last edited by
              #6

              OOPS! yeah you are right I'm such an idiot! lol Thank you so much!

              C 1 Reply Last reply
              0
              • F Farhad Eft

                Hi Can anybody help me please. when i try to login in my asp.net 4 page with the following source code an error returns: DataTable dt = new DataTable(); DataSet ds = new DataSet(); SqlConnection sqlConn = new SqlConnection(ConfigurationManager.ConnectionStrings["SN11ConnectionString"].ConnectionString); SqlCommand sqlCmd = new SqlCommand("SELECT UserId FROM [Users] WHERE ([Email]=@Email AND [Password]=@Password", sqlConn); //Create the parameters SqlParameter paramEmail; paramEmail = new SqlParameter("@Email", SqlDbType.NVarChar, 25); paramEmail.Value = TextBoxLoginEmail.Text; sqlCmd.Parameters.Add(paramEmail); //Hash the password MD5CryptoServiceProvider md5Hasher = new MD5CryptoServiceProvider(); byte[] hashedBytes; UTF8Encoding encoder = new UTF8Encoding(); hashedBytes = md5Hasher.ComputeHash(encoder.GetBytes(TextBoxLoginPassword.Text)); SqlParameter paramPwd; paramPwd = new SqlParameter("@Password", SqlDbType.Binary, 16); paramPwd.Value = hashedBytes; sqlCmd.Parameters.Add(paramPwd); sqlConn.Open(); SqlDataAdapter sda = new SqlDataAdapter(sqlCmd); sda.Fill(ds); dt = ds.Tables[0]; Here is the error message that appears when i press the login button: Incorrect syntax near '@Password'. Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. Exception Details: System.Data.SqlClient.SqlException: Incorrect syntax near '@Password'. Source Error: Line 57: sqlConn.Open(); Line 58: SqlDataAdapter sda = new SqlDataAdapter(sqlCmd); Line 59: sda.Fill(ds); Line 60: dt = ds.Tables[0]; Line 61: } Thank you.

                L Offline
                L Offline
                Lost User
                wrote on last edited by
                #7

                I would think a hashed password, even of a password only a few characters long, might be considerably longer than 16 bytes? Not sure, but could that be the problem? Edit: Sorry I think I have put you wrong. I was thinking the hex version of hashes possibly.

                modified on Saturday, April 2, 2011 5:13 PM

                1 Reply Last reply
                0
                • F Farhad Eft

                  OOPS! yeah you are right I'm such an idiot! lol Thank you so much!

                  C Offline
                  C Offline
                  C Coudou
                  wrote on last edited by
                  #8

                  you're welcome. lol. :-D

                  C# コードMicrosoft End User 2000-2008 「「「「「「「「「「「「「「「「「「「「「「「「「「「「 The best things in life are free 」」」」」」」」」」」」」」」」」」」」」」」」」」」」

                  1 Reply Last reply
                  0
                  • F Farhad Eft

                    Hi Can anybody help me please. when i try to login in my asp.net 4 page with the following source code an error returns: DataTable dt = new DataTable(); DataSet ds = new DataSet(); SqlConnection sqlConn = new SqlConnection(ConfigurationManager.ConnectionStrings["SN11ConnectionString"].ConnectionString); SqlCommand sqlCmd = new SqlCommand("SELECT UserId FROM [Users] WHERE ([Email]=@Email AND [Password]=@Password", sqlConn); //Create the parameters SqlParameter paramEmail; paramEmail = new SqlParameter("@Email", SqlDbType.NVarChar, 25); paramEmail.Value = TextBoxLoginEmail.Text; sqlCmd.Parameters.Add(paramEmail); //Hash the password MD5CryptoServiceProvider md5Hasher = new MD5CryptoServiceProvider(); byte[] hashedBytes; UTF8Encoding encoder = new UTF8Encoding(); hashedBytes = md5Hasher.ComputeHash(encoder.GetBytes(TextBoxLoginPassword.Text)); SqlParameter paramPwd; paramPwd = new SqlParameter("@Password", SqlDbType.Binary, 16); paramPwd.Value = hashedBytes; sqlCmd.Parameters.Add(paramPwd); sqlConn.Open(); SqlDataAdapter sda = new SqlDataAdapter(sqlCmd); sda.Fill(ds); dt = ds.Tables[0]; Here is the error message that appears when i press the login button: Incorrect syntax near '@Password'. Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. Exception Details: System.Data.SqlClient.SqlException: Incorrect syntax near '@Password'. Source Error: Line 57: sqlConn.Open(); Line 58: SqlDataAdapter sda = new SqlDataAdapter(sqlCmd); Line 59: sda.Fill(ds); Line 60: dt = ds.Tables[0]; Line 61: } Thank you.

                    S Offline
                    S Offline
                    SamRST
                    wrote on last edited by
                    #9

                    hi, the problem is simple. look your sql deeply. there is an error You sql = SELECT UserId FROM [Users] WHERE ([Email]=@Email AND [Password]=@Password hope u got the mark. there is a open bracket be the email which will fail the query result. Good luck.

                    1 Reply Last reply
                    0
                    Reply
                    • Reply as topic
                    Log in to reply
                    • Oldest to Newest
                    • Newest to Oldest
                    • Most Votes


                    • Login

                    • Don't have an account? Register

                    • Login or register to search.
                    • First post
                      Last post
                    0
                    • Categories
                    • Recent
                    • Tags
                    • Popular
                    • World
                    • Users
                    • Groups