Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to put condition equal to two strings

I am working on an ATM college project.

When a user enters his password in a textbox, the password is saved in the database.

I want to compare the password entered in a textbox with the password saved in database. I am getting the password from database but cannot put an equal statement.

The code is as follows:

SqlDataReader rdr = cmd.ExecuteReader();
if (rdr.Read())
{
    string cus_pin = rdr["pin"].ToString();
    string cus_pin_byuser = textBox1.ToString();

    if (string.Equals(cus_pin, cus_pin_byuser) == true)
    {
        cust_main cm = new cust_main();
        cm.label1.Text = label7.Text;
        cm.label2.Text = label6.Text;
        cm.label4.Text = label8.Text;

        CodeVer codeVer = new CodeVer();

        codeVer.getUserAccountNumber(name);
        codeVer.Show();

        this.Close();
    }
    else
    {
        MessageBox.Show("Invalid Pin");
    }
}
like image 657
AhmAr KAka Avatar asked Mar 02 '26 07:03

AhmAr KAka


1 Answers

I think you might be applying .ToString() on the textBox object. I suppose you want to use textBox1.Text.

So the code would become:

...
string cus_pin = rdr["pin"].ToString()
string cus_pin_byuser = textBox1.Text; 

if (cus_pin == cus_pin_byuser)
...

Also, please note that it is really insecure to store the user's password as plain text. Please store it's hashed version. I really recommend reading on the OWASP's password storage cheat sheet.

like image 168
Peterson V Avatar answered Mar 03 '26 20:03

Peterson V



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!