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. General Programming
  3. C#
  4. Mysql Query Error

Mysql Query Error

Scheduled Pinned Locked Moved C#
databasemysqlhelpquestion
3 Posts 3 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.
  • N Offline
    N Offline
    N Mohamed rafi
    wrote on last edited by
    #1

    I have stored userid and password in mysql database, this query is showing login successfully for not stored data, so please correct it

    string query = "select * from login where userid=@userid and password=@password";
    using (MySqlCommand cmd = new MySqlCommand(query))
    {
    cmd.Parameters.AddWithValue("@userid", id);
    cmd.Parameters.AddWithValue("@password", password);
    cmd.Connection = cnn;
    cnn.Open();
    cmd.ExecuteNonQuery();
    DialogResult dr = MessageBox.Show("Are you sure to Login now?", "Confirmation Message", MessageBoxButtons.YesNo);
    if (dr == DialogResult.Yes)
    {
    MessageBox.Show("Login Successfully");
    cnn.Close();
    this.Hide();
    Form2 f2 = new Form2();
    f2.ShowDialog();

    D OriginalGriffO 2 Replies Last reply
    0
    • N N Mohamed rafi

      I have stored userid and password in mysql database, this query is showing login successfully for not stored data, so please correct it

      string query = "select * from login where userid=@userid and password=@password";
      using (MySqlCommand cmd = new MySqlCommand(query))
      {
      cmd.Parameters.AddWithValue("@userid", id);
      cmd.Parameters.AddWithValue("@password", password);
      cmd.Connection = cnn;
      cnn.Open();
      cmd.ExecuteNonQuery();
      DialogResult dr = MessageBox.Show("Are you sure to Login now?", "Confirmation Message", MessageBoxButtons.YesNo);
      if (dr == DialogResult.Yes)
      {
      MessageBox.Show("Login Successfully");
      cnn.Close();
      this.Hide();
      Form2 f2 = new Form2();
      f2.ShowDialog();

      D Offline
      D Offline
      Dave Kreskowiak
      wrote on last edited by
      #2

      You're STILL begging other people to do your work for you. Do you have any idea what ExecuteNoQuery does? No? READ THE DOCUMENTATION ON IT[^]! It returns a value you're not examining at all. You're actually throwing it away! And why would you ask the user if they want to login AFTER they enter credentials you try to to check them against the data? That makes no sense. Why would you put the code to close the database connection dependent on the result of a messagebox?

      Asking questions is a skill CodeProject Forum Guidelines Google: C# How to debug code Seriously, go read these articles.
      Dave Kreskowiak

      1 Reply Last reply
      0
      • N N Mohamed rafi

        I have stored userid and password in mysql database, this query is showing login successfully for not stored data, so please correct it

        string query = "select * from login where userid=@userid and password=@password";
        using (MySqlCommand cmd = new MySqlCommand(query))
        {
        cmd.Parameters.AddWithValue("@userid", id);
        cmd.Parameters.AddWithValue("@password", password);
        cmd.Connection = cnn;
        cnn.Open();
        cmd.ExecuteNonQuery();
        DialogResult dr = MessageBox.Show("Are you sure to Login now?", "Confirmation Message", MessageBoxButtons.YesNo);
        if (dr == DialogResult.Yes)
        {
        MessageBox.Show("Login Successfully");
        cnn.Close();
        this.Hide();
        Form2 f2 = new Form2();
        f2.ShowDialog();

        OriginalGriffO Offline
        OriginalGriffO Offline
        OriginalGriff
        wrote on last edited by
        #3

        To add to what David has said, you are also putting yourself at quite considerable risk: Never store passwords in clear text - it is a major security risk. There is some information on how to do it here: Password Storage: How to do it.[^] And remember: if this is web based and you have any European Union users then GDPR applies and that means you need to handle passwords as sensitive data and store them in a safe and secure manner. Text is neither of those and the fines can be .... um ... outstanding. In December 2018 a German company received a relatively low fine of €20,000 for just that. The more I see of "your code" the more I think you aren't anywhere near ready for whatever it is you are trying to do ...

        "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt AntiTwitter: @DalekDave is now a follower!

        "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
        "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt

        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