Click here to Skip to main content
15,914,594 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
This Code for Login Form But Not Check If The Later Capital Or Not
How Can Check If The User Write The Sam Word In Database



SqlCommand myCommand = default(SqlCommand);

myCommand = new SqlCommand("SELECT Username,PasswordUser FROM LoginTbl WHERE Username = @Username AND PasswordUser = @Password", myConnection);

SqlParameter uName = new SqlParameter("@Username", SqlDbType.VarChar);
SqlParameter uPassword = new SqlParameter("@Password", SqlDbType.VarChar);

uName.Value = txtUserName.Text;
uPassword.Value = txtPassword.Text;

myCommand.Parameters.Add(uName);
myCommand.Parameters.Add(uPassword);

myCommand.Connection.Open();

SqlDataReader myReader = myCommand.ExecuteReader(CommandBehavior.CloseConnection);

if (myReader.Read() == true)
{
//MessageBox.Show("You have logged in successfully " + txtUserName.Text);
//Hide the login form
this.Hide();
FormMAIN2 fm = new FormMAIN2();
fm.ShowDialog();
Application.Exit();
}


else
{
MessageBox.Show("Login Failed...Try again !", "Login Denied", MessageBoxButtons.OK, MessageBoxIcon.Error);

txtUserName.Clear();
txtPassword.Clear();
txtUserName.Focus();

}
Posted

Don't.
Please, don't store passwords in clear text - it's a major security risk: http://www.commitstrip.com/wp-content/uploads/2013/09/Strips-Erreur-au-pilori-001-650-finalenglish.jpg[^]

See here: Password Storage: How to do it.[^] - it should help.
 
Share this answer
 
Comments
Member 11280947 4-May-15 8:10am    
What I Do I Cant Under Stand
OriginalGriff 4-May-15 8:21am    
Read the link!
OriginalGriff 4-May-15 8:22am    
Read both links - the second one explains what to do.
Do not store passwords in plain text!

This is a common mistake and there are many good articles about this topic here on codeproject.

I think this one should cover you, including the database access:
Beginners guide to a secure way of storing passwords[^]

For more in-depth information about password security, please see here:
Salted Password Hashing - Doing it Right[^]

If you want to look at more articles, here's the Google search:
https://www.google.com/search?q=codeproject+salted+hashing&ie=utf-8&oe=utf-8[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900