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. Password Checking

Password Checking

Scheduled Pinned Locked Moved C#
helpcss
2 Posts 2 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.
  • A Offline
    A Offline
    ASGill
    wrote on last edited by
    #1

    Hi...im trying to do password checking for multiple users... the problem is that i get a runtime error saying the specified cast is invalid(line 272) ...i've check that im getting a string...so what could the problem be private void btnOK_Click(object sender, System.EventArgs e) { dataSetPWD.Clear(); if(txtPassword.Text.Length > 10 && txtPassword.Text != "") { MessageBox.Show("The password textbox should contain more than 1 character and less than 10 characters. Please check your password.","Information"); } else { try { oleDbConnection1.Open(); oleDbDataAdapter1.SelectCommand.CommandText = "SELECT UserType FROM Password WHERE UserName = '"+txtUsername.Text+"' AND Password = '"+txtPassword.Text+"'"; oleDbDataAdapter1.Fill(dataSetPWD); System.Data.DataTable Password = dataSetPWD.Tables[0]; if(Password.Rows.Count != 0) { string s = (string) Password.Rows[0][0]; --> LINE 272 s.Trim(); s.ToString(); if(s.Equals("reception")) { frmReception rm = new frmReception(); rm.Show(); } else if(s.Equals("doctor")) { frmDiagnosis dm = new frmDiagnosis(); dm.Show(); } else if(s.Equals("pharmacy")) { frmPharMenu pm = new frmPharMenu(); pm.Show(); } /*if(s.Equals("cashier")) { frmCashier cm = new frmCashier(); cm.Show(); }*/ else { MessageBox.Show("Invalid Password or User Name. Please check your user name and password. It is case sensitive","Invalid Entry"); } } else { MessageBox.Show("No Such Record"); } } catch (Exception ErrorPassword) { MessageBox.Show(ErrorPassword.ToString(),"Password Error"); } finally { oleDbConnection1.Close(); oleDbConnection1.Dispose(); } } } CODER

    M 1 Reply Last reply
    0
    • A ASGill

      Hi...im trying to do password checking for multiple users... the problem is that i get a runtime error saying the specified cast is invalid(line 272) ...i've check that im getting a string...so what could the problem be private void btnOK_Click(object sender, System.EventArgs e) { dataSetPWD.Clear(); if(txtPassword.Text.Length > 10 && txtPassword.Text != "") { MessageBox.Show("The password textbox should contain more than 1 character and less than 10 characters. Please check your password.","Information"); } else { try { oleDbConnection1.Open(); oleDbDataAdapter1.SelectCommand.CommandText = "SELECT UserType FROM Password WHERE UserName = '"+txtUsername.Text+"' AND Password = '"+txtPassword.Text+"'"; oleDbDataAdapter1.Fill(dataSetPWD); System.Data.DataTable Password = dataSetPWD.Tables[0]; if(Password.Rows.Count != 0) { string s = (string) Password.Rows[0][0]; --> LINE 272 s.Trim(); s.ToString(); if(s.Equals("reception")) { frmReception rm = new frmReception(); rm.Show(); } else if(s.Equals("doctor")) { frmDiagnosis dm = new frmDiagnosis(); dm.Show(); } else if(s.Equals("pharmacy")) { frmPharMenu pm = new frmPharMenu(); pm.Show(); } /*if(s.Equals("cashier")) { frmCashier cm = new frmCashier(); cm.Show(); }*/ else { MessageBox.Show("Invalid Password or User Name. Please check your user name and password. It is case sensitive","Invalid Entry"); } } else { MessageBox.Show("No Such Record"); } } catch (Exception ErrorPassword) { MessageBox.Show(ErrorPassword.ToString(),"Password Error"); } finally { oleDbConnection1.Close(); oleDbConnection1.Dispose(); } } } CODER

      M Offline
      M Offline
      mav northwind
      wrote on last edited by
      #2

      You could use .ToString() instead of (string) to see what you actually get. Could it be that Column[0] isn't the user type you expect? I think it would be more robust and easier to read if you used Password.Rows["UserType"][0] (or whatever your column's name is)... BTW, the first if clause is wrong :suss:. It won't get passwords that are too short. You should change && for ||. Regards, mav

      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